java - How to calculate tab length till the end of the String? -
this question has answer here:
- java string split removed empty values 4 answers
i spliting string tab
string s = "1"+"\t"+2+"\t"+3+"\t"+"4"; system.out.println("length : "+ s.split("\\t").length);
in case length 4. if remove last element 4 & give blank, like
string s = "1"+"\t"+2+"\t"+3+"\t"+""; system.out.println("length : "+ s.split("\\t").length);
in case got output 3. means not calculating last tab. in below case also, need length 4. scenario using in project & getting undesired result. please suggest me, how calculate entire length of tab delimited string, whether last element blank. such as, if case is,
string s = "1"+"\t"+2+"\t"+3+"\t"+""; system.out.println("length : "+ s.split("\\t").length);
then answer should 4 & if case is,
string s = "1"+"\t"+2+"\t"+3+"\t"+"" + "\t"+ ""; system.out.println("length : "+ s.split("\\t").length);
then answer should 5.
please provide me appropriate answer.
to prevent split
removing trailing empty spaces need use split(string regex, int limit)
negative limit
value
split("\t", -1)
Comments
Post a Comment