java - How to calculate tab length till the end of the String? -


this question has answer here:

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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -