I want to split the string based on some special character and display the splitted values accordingly. My job is to get the values from the text fileds append it with some special charater and store it in database. While displaying retrieve data split and display accordingly..
let us assume i have to get data from 10 text fileds now my String format is String str=data1^^^data4^^^^^^ ; Now tell me how do i retrieve data which is comming from the 5th/6th/7th textfiled here it is empty.How to test it dynamically and retrieve accordingly? when i use split i will get array length as 4....so while retrieving every time i have to check for array length and retrive based on it. ie. if array length is 4 i can retrieve upto 4 values and make others empty. but what if there are 100 text fields and if 50 are empty....here comes the problem i cant check for each and every time.
this array length varies based on the data entered.. hope you people will understand my problem? Tell me the better way of doing it..
Indeed, String.split(...) works like you describe - if there are empty fields after the last filled field, they will be omitted from the result array. You could write a simple helper method to make it easier:
[ August 17, 2007: Message edited by: Jesper Young ]
Originally posted by Red Smith: I was gonna say use StringTokenizer, but it also behaves improperly. They must have both been designed by someone who doesn't have a need to parse delimited input lines.
Another option is to use the overloaded version of the split() method that doesn't delete trailing zero-length matches.