Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,805,829 Members 42,110 Now Online
XDA Developers Android and Mobile Development Forum

Replace substring from inputText

Tip us?
 
fikriakhdi
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: Mar 2014
Smile Replace substring from inputText

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
 
Archer
Old
#2  
Archer's Avatar
Senior Moderator / Recognized Developer - (Un)Recognized Pole Dancer
Thanks Meter 4,017
Posts: 13,767
Join Date: Jul 2008
Location: Northampton
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");
.
"I live by my own rules, nobody else's, not even my own."
.
My xda links

New User Guide | XDA Forum Rules | 10 Posts - Why and How? | Admins & Mods | My xda Bookmarks

.

.
 
fikriakhdi
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: Mar 2014
Quote:
Originally Posted by Archer View Post
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
 
LinuxForce
Old
#4  
Junior Member
Thanks Meter 0
Posts: 6
Join Date: Mar 2014
Where do you call these methods ?
Code:
ngeji(EditText editText)
normalin(EditText editText)
 
Archer
Old
#5  
Archer's Avatar
Senior Moderator / Recognized Developer - (Un)Recognized Pole Dancer
Thanks Meter 4,017
Posts: 13,767
Join Date: Jul 2008
Location: Northampton
Quote:
Originally Posted by fikriakhdi View Post
Thanks for the solution , but i'm still stuck in the error...maybe i have a wrong code
can you fix up my code?
Quote:
Originally Posted by LinuxForce View Post
Where do you call these methods ?
Code:
ngeji(EditText editText)
normalin(EditText editText)
^^ This, and what errors do you have?
.
"I live by my own rules, nobody else's, not even my own."
.
My xda links

New User Guide | XDA Forum Rules | 10 Posts - Why and How? | Admins & Mods | My xda Bookmarks

.

.
 
arpitkh96
Old
#6  
arpitkh96's Avatar
Senior Member
Thanks Meter 384
Posts: 1,093
Join Date: Feb 2012
Location: 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes