Link to home
Start Free TrialLog in
Avatar of rmvprasad
rmvprasad

asked on

String.split() function not working properly

I have a delimiter="*&?";
I have a string,each word is seperated by a delimiter and at the end of the string I have appended an integer(concerted it into string and appended). If I used String.Split(Delimiter) function each string seperated by the delimiter should be stored in an array. But the last string (which was a num converted to string) is still along with delimiter
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Please post the string and your code
Avatar of rmvprasad
rmvprasad

ASKER

String str = "<Make>Computer General</Make>"
            +"<Model>Wizbang 1900</Model>"
            +"<Warranty>T</Warranty>"
            +"<Maintenance>F</Maintenance>";

String DELIMITER            = ":$*";
int childIndex                        = 0;

String temp = String.valueOf(childIndex);;
treeString = tag.substring(leftAngleIndex+1,rightAngleIndex);
treeString = treeString + DELIMITER;
treeString = treeString + EMPTYSPACE;
treeString = treeString + temp;

String[] treeStringArr      = treeString.split(DELIMITER);
Can you just post the value of  treeString
u need to escape the charas in that regex

String[] treeStringArr      = treeString.split("\\:\\$\\*");

or better use a different delimiter

String DELIMITER            = "___";

though the code you posted you don't actually need to split:

String[] treeStringArr      = new String[] { tag.substring(leftAngleIndex+1,rightAngleIndex), treeString + EMPTYSPACE + temp};
ASKER CERTIFIED SOLUTION
Avatar of avya2k
avya2k

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
as 1-9 are non printable chars