Replace substring from inputText

Search This thread

fikriakhdi

New member
Mar 25, 2014
2
0
Hello all :)
i'm newbie
i just want to ask..
how to replace substring from textinput/input text?
this is my code
public void ngeji(EditText editText){
EditText editteks = (EditText) findViewById(R.id.editText1);
String str = editteks.getText().toString();
if(str!= null){
str.toUpperCase();
str.replaceAll("U", "OO");
str.replaceAll("C", "TJ");
str.replaceAll("F", "EV");
str.replaceAll("ES", "X");
str.replaceAll("EKS", "X");
editText.setText(str);}
}
public void normalin(EditText editText){
EditText editteks = (EditText) findViewById(R.id.editText2);
String str = editteks.getText().toString();
if(str!=null){
str.toLowerCase();
str.replaceAll("oo", "u");
str.replaceAll("tj", "c");
str.replaceAll("ev", "f");
str.replaceAll("x", "eks");
str.replaceAll("y", "i");
str.replaceAll("q", "k");
editText.setText(str);
}
}

what's wrong with the code?


btw i just wanna make translator...its like ticky word translator
for example
i = OO
j = DJ
and Uppercase all
when i type : juanda
so... the result is DJOOANDA

i'll wait for your reply
thanks :eek:
 

Archer

Inactive Recognized Developer / Retired Senior Mod
Jul 9, 2008
14,002
4,003
Manchester
Google Pixel 8 Pro
Both .toUpperCase() and .replaceAll() return a string - they do not affect the string that you run them against. So this will do nothing...

Code:
str.toUpperCase();
str.replaceAll("U", "OO");
str.replaceAll("C", "TJ");
str.replaceAll("F", "EV");
str.replaceAll("ES", "X");
str.replaceAll("EKS", "X");

This is what you want...

Code:
str = str.toUpperCase();
str = str.replaceAll("U", "OO");
str = str.replaceAll("C", "TJ");
str = str.replaceAll("F", "EV");
str = str.replaceAll("ES", "X");
str = str.replaceAll("EKS", "X");
 

fikriakhdi

New member
Mar 25, 2014
2
0
Both .toUpperCase() and .replaceAll() return a string - they do not affect the string that you run them against. So this will do nothing...

Code:
str.toUpperCase();
str.replaceAll("U", "OO");
str.replaceAll("C", "TJ");
str.replaceAll("F", "EV");
str.replaceAll("ES", "X");
str.replaceAll("EKS", "X");

This is what you want...

Code:
str = str.toUpperCase();
str = str.replaceAll("U", "OO");
str = str.replaceAll("C", "TJ");
str = str.replaceAll("F", "EV");
str = str.replaceAll("ES", "X");
str = str.replaceAll("EKS", "X");


Thanks for the solution :), but i'm still stuck in the error...maybe i have a wrong code :(
can you fix up my code?

this is my code
Code:
package com.example.qdjytranslator;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
	public void ngeji(EditText editText){
		EditText editteks = (EditText) findViewById(R.id.editText1);
		String str = editteks.getText().toString();
		if(str!= null){
			str = str.toUpperCase();
			str = str.replace("U", "OO");
			str = str.replace("C", "TJ");
			str = str.replace("F", "EV");
			str = str.replace("ES", "X");
			str = str.replace("EKS", "X");
			editText.setText(str);
			}
	}
	public void normalin(EditText editText){
		EditText editteks = (EditText) findViewById(R.id.editText2);
		String str = editteks.getText().toString();
		if(str!=null){
			str = str.toLowerCase();
			str = str.replace("oo", "u");
			str = str.replace("tj", "c");
			str = str.replace("ev", "f");
			str = str.replace("x", "eks");
			editText.setText(str);
		}
	}
	
	public void onTerminate()
	{
		super.onDestroy();
		this.finish();
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}



i'll waiting for your reply :)
 

arpitkh96

Senior Member
Feb 17, 2012
1,156
645
27
panipat
Why are you using an edittext as an input for both functions when you are not using it.just leave brackets empty
public void function()
{
}

Sent from my GT-S5570 using XDA Premium 4 mobile app