Home arrow static arrow Java Programming [Archive] - Inseting a char in a string?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Inseting a char in a string?
This topic has 3 replies on 1 page.

Posts:173
Registered: 6/13/00
Inseting a char in a string?  
Aug 1, 2004 11:09 AM



 
Hi,
Any method available to insert a character at a specific position in a string?

example:
st = "abde" <------ Original string
st= "abCde" <------ Add "C" in position 2
 

Posts:79
Registered: 11/2/00
Re: Inseting a char in a string?  
Aug 1, 2004 11:21 AM (reply 1 of 3)



 
Any method available to insert a character at a
specific position in a string?

example:
st = "abde" <------ Original string
st= "abCde" <------ Add "C" in position 2

You can do it so:
String st = new String("abcde");
st = StringBuffer(st).insert(2,new Char("C")).toString();

With kind regards
F.-M. Jaeschke
 

Posts:79
Registered: 11/2/00
Re: Inseting a char in a string?  
Aug 1, 2004 11:23 AM (reply 2 of 3)



 
You can do it so:
String st = new String("abcde");
st = StringBuffer(st).insert(2,new
Char("C")).toString();
Sorry there there is an error:

it must be
String st = new String("abcde");st = StringBuffer(st).insert(2,"C").toString();

With kind regards
F.-M. Jaeschke
 

Posts:173
Registered: 6/13/00
Re: Inseting a char in a string?  
Aug 2, 2004 10:11 AM (reply 3 of 3)



 
Works good. Thanks.
 
This topic has 3 replies on 1 page.