TextView स्ट्रिंग से स्वर (Vowels) हटाना
यह उदाहरण दर्शाता है कि Android में TextView स्ट्रिंग से सभी स्वर (vowels) कैसे हटाए जाते हैं।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project पर जाएं और प्रोजेक्ट बनाएं।
चरण 2: लेआउट फ़ाइल (res/layout/activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:hint="नाम दर्ज करें"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:id="@+id/save" android:text="सेव करें"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
चरण 3: MainActivity.java
package com.example.myapp;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText name;
TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
textview = findViewById(R.id.textview);
findViewById(R.id.save).setOnClickListener(v -> {
String input = name.getText().toString();
if (!input.isEmpty()) {
// सभी स्वर (बड़े और छोटे) हटाएं
String result = input.replaceAll("[AEIOUaeiou]", "");
textview.setText(result);
Toast.makeText(this, "स्वर हटाए गए", Toast.LENGTH_LONG).show();
} else {
name.setError("नाम दर्ज करें");
}
});
}
}
ऐप चलाएं
डिवाइस कनेक्ट करें और ऐप चलाएं।

परिणाम में, हम नाम दर्ज कर रहे हैं लेकिन TextView बिना स्वरों के टेक्स्ट दिखा रहा है। रेगुलर एक्सप्रेशन [AEIOUaeiou] सभी अंग्रेजी स्वरों को मैच करता है। हिंदी स्वरों के लिए यूनिकोड रेंज का उपयोग करें।