October 9th, 2002, 07:02 PM

Linefeed translation "\n" in length()
Guys,
Newbie java guy here. I'm trying to construct a string where I may have tabs and definately have linefeed \n. This is what I'm doing:
parms = "<*INBOUND*>\t<OUTBOUND>\n";
Then I'm trying to find the length of the string using:
length = parms.length(parms);
This is return the length as if the \t and \n were literally 2 characters each. What I need is the length when the \t and \n are translated. So \n should be 1 character and \t can actually vary. Is there any way to do this?
I need length to be 26. The \t in the example above would be 4 characters and the \n would be 1.
Any pointers for me??
October 9th, 2002, 08:19 PM

trim it (see the String class method list), and do the length count off of that.
Brett
October 10th, 2002, 09:30 AM

I think that both \t and \n are read as one char each when using length(). You could check the length and then find the number of \t in the string and add that number times 3 to come up with the desired length of 4 per instance of \t. I don't think using trim will be helpful for you in what you're looking for, but maybe I misunderstand...
October 10th, 2002, 02:28 PM

Well, I must have been smoking something.....
jfhiller is right the \t and \n are seen as one character, as it should be. And so the length is correct after all. When it is displayed, the \t and \n are translated properly and I don't even have to worry about it.
Using trim() simply cut the \n off the end as it removes all white space from either end.
Thanks guys!