Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 9th, 2002, 07:02 PM
noslenj123 noslenj123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Phoenix, AZ
Posts: 482 noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 21 h 34 m 11 sec
Reputation Power: 30
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??

Reply With Quote
  #2  
Old October 9th, 2002, 08:19 PM
estrabd's Avatar
estrabd estrabd is offline
o0o.o0o
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: m00n
Posts: 184 estrabd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 48 sec
Reputation Power: 8
Send a message via ICQ to estrabd Send a message via AIM to estrabd Send a message via Yahoo to estrabd
trim it (see the String class method list), and do the length count off of that.

Brett

Reply With Quote
  #3  
Old October 10th, 2002, 09:30 AM
jfhiller jfhiller is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 1 jfhiller User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to jfhiller
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...

Reply With Quote
  #4  
Old October 10th, 2002, 02:28 PM
noslenj123 noslenj123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Phoenix, AZ
Posts: 482 noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level)noslenj123 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 21 h 34 m 11 sec
Reputation Power: 30
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Linefeed translation "\n" in length()


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway