|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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?? |
|
#2
|
||||
|
||||
|
trim it (see the String class method list), and do the length count off of that.
Brett |
|
#3
|
|||
|
|||
|
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...
|
|
#4
|
|||
|
|||
|
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! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Linefeed translation "\n" in length() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|