Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Smile Replace substring from inputText

OP fikriakhdi

25th March 2014, 07:21 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
2 posts
Join Date:Joined: Mar 2014
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
25th March 2014, 11:08 AM   |  #2  
Archer's Avatar
Senior Moderator / Recognized Developer - (Un)Recognized Pole Dancer
Flag Northampton
Thanks Meter: 4,117
 
10
13,913 posts
Join Date:Joined: Jul 2008
More
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");
26th March 2014, 02:03 AM   |  #3  
OP Junior Member
Thanks Meter: 0
 
2 posts
Join Date:Joined: Mar 2014
Quote:
Originally Posted by Archer

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
28th March 2014, 11:28 AM   |  #4  
Junior Member
Thanks Meter: 0
 
6 posts
Join Date:Joined: Mar 2014
More
Where do you call these methods ?
Code:
ngeji(EditText editText)
normalin(EditText editText)
28th March 2014, 12:55 PM   |  #5  
Archer's Avatar
Senior Moderator / Recognized Developer - (Un)Recognized Pole Dancer
Flag Northampton
Thanks Meter: 4,117
 
10
13,913 posts
Join Date:Joined: Jul 2008
More
Quote:
Originally Posted by fikriakhdi

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

Where do you call these methods ?

Code:
ngeji(EditText editText)
normalin(EditText editText)

^^ This, and what errors do you have?
28th March 2014, 07:54 PM   |  #6  
arpitkh96's Avatar
Senior Member
Flag panipat
Thanks Meter: 553
 
1,126 posts
Join Date:Joined: Feb 2012
Donate to Me
More
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
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes