#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Phoenix, AZ
    Posts
    484
    Rep Power
    36

    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. #2
  3. o0o.o0o
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    m00n
    Posts
    194
    Rep Power
    102
    trim it (see the String class method list), and do the length count off of that.

    Brett
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    1
    Rep Power
    0
    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...
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Phoenix, AZ
    Posts
    484
    Rep Power
    36
    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!

IMN logo majestic logo threadwatch logo seochat tools logo