| Author |
string and array
|
Suka Hati
Ranch Hand
Joined: Oct 28, 2004
Posts: 56
|
|
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
Joined: Sep 28, 2004
Posts: 1228
|
|
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.
|
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
|
 |
Yosi Hendarsjah
Ranch Hand
Joined: Oct 02, 2003
Posts: 164
|
|
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
Joined: Oct 02, 2003
Posts: 164
|
|
FYI, in Indonesian and Malay language, Suka Hati means happy.
|
 |
Yosi Hendarsjah
Ranch Hand
Joined: Oct 02, 2003
Posts: 164
|
|
|
I mean, in Indonesia (and I think also in Malaysia), Suka Hati is not a common person's name.
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
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 ]
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Suka Hati
Ranch Hand
Joined: Oct 28, 2004
Posts: 56
|
|
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
Joined: Oct 02, 2003
Posts: 164
|
|
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 ]
|
 |
 |
|
|
subject: string and array
|
|
|