Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string and array

 
Suka Hati
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...
i have a string array.examples i have first element like this; you-and-i.
for each element in the array...i want to delete the '-'and change it with and '' character...
this mean that the examples will be youandi.....how to do this???
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
replaceAll(String regex, String replacement) in java.lang.String might help you

This method replaces each substring of this string that matches the given regular expression with the given replacement.
 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, looks like class assignment to me.
Why don't you look at the Java API documentation for String and StringBuffer class.

BTW, are you from Indonesia or Malaysia? Please use your real name (unless Suka Hati is your real name).
[ March 02, 2005: Message edited by: Yosi Hendarsjah ]
 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI, in Indonesian and Malay language, Suka Hati means happy.
 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean, in Indonesia (and I think also in Malaysia), Suka Hati is not a common person's name.
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the input, Yosi Hendarsjah. It is useful information for us moderators who don't speak Indonesian/Malaysian.
[ March 04, 2005: Message edited by: Marilyn de Queiroz ]
 
Suka Hati
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hehe...yeah...sukahati means happy....
back to my question......

i have a string array[5].examples i have first element like this; you-and-i.
for each element in the array...i want to delete the '-'and change it with and '' character...
this mean that the examples will be youandi.....how to do this???

i want to delete all '-' in every element of that array....i try to to a looping, in every looping....the element involve....i use indexOf to get where the '-' is and then use deleteCharAt...like below cooding

StringBuffer cTest = new StringBuffer(outputPos[finaltest]);
int tryElement;
tryElement=(outputPos[finaltest]).indexOf("-");
cTest=cTest.deleteCharAt(tryElement);

but tryElement send a negetif value....how to solve this problem
 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code, when searching for substring "-", you searched in the String object. But when deleting, you used the StringBuffer object. So, after first deletion, the contents of the String object and the StringBuffer object are not the same anymore. And you may delete the wrong character. And if indexOf method returns negative value, it means there are no substring you are searching for in the String or StringBuffer object.

[ March 07, 2005: Message edited by: Yosi Hendarsjah ]
[ March 07, 2005: Message edited by: Yosi Hendarsjah ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic