Am I just blind or is there no remove() function in a string? Say I want to remove the 2nd character of the string, the only way I've found is to build a new string of the two substrings (all characters before the one I want to remove and all the ones behind). I know it's not posible to change a string, but is there a method that returnes a new string without the character I don't want there? /Mike
I considered StringBuffers as well, however, unless you're going to be doing serveral manipulations on the String you might as well just do it using String.substring. A custom utility class might be nice as well if it's something you are doing a lot.
What I was doing was a small program printing all permutations of a set of characters. I could find a way to remove the "used" character, so I ended up using substring. I will have to look into the StringBuffer-class.. Thanx /Mike
Actually, I tried that first myself and it simply creates a space. The problem is that you can't call replace like this (using strings - there's no string method defined for this) String.replace( String s1, String s2 ); If you could do this then you could pass an empty string (or maybe even a null value). Unfortunately, the remove method only accepts characters and, being primatives, you can't assign a null value and '' to a character. The only way would be to do this, s.replace( s.charAt( 1 ), ' ' ); But this leaves and empty space in the resulting string "a cde" Sean