user
user

Reputation: 17

To change the character to string

Have to change the character "^" to "255E"

String s_ysymbol = c1.getString(c1.getColumnIndex(DBConstants.YSYMBOL));

in this ysymbol starting charecter will be ^ have to change it to 255E and then have to do further process.. I tried the replace method

s_ysymbol.replace("^","255E");

but it not changing.. can anybody provide solution..

Upvotes: 0

Views: 92

Answers (3)

Wang Wei
Wang Wei

Reputation: 583

just look into the source code of class String.

public final class String{
....
}

Please pay attention to the key word final. It means that String object can't be changed. So all of the methods in class String don't change the object itself, but create new String object and return to the new object. That's why only " s_ysymbol.replace("^","255E"); " doesn't make any changes.

s_ysymbol = s_ysymbol.replace("^","255E");

this will work.

Upvotes: 1

toniedzwiedz
toniedzwiedz

Reputation: 18553

replace returns another instance of String, you can't modify an existing one so an assignment is required.

s_ysymbol = s_ysymbol.replace("^","255E");

Alternatively, you could use replaceFirst or replaceAll to pass a regular expression and change the first occurrence or all occurrences of it. In such case, you'd have to use an escape character.

s_ysymbol = s_ysymbol.replaceFirst("\^","255E");

Upvotes: 1

Mohammad Ersan
Mohammad Ersan

Reputation: 12444

try this s_ysymbol = s_ysymbol.replace("^","255E");

Upvotes: 3

Related Questions