Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

carriage return

 
Manuel Paco
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to find out if my String "str" contains carriage return.
Would you take a look please what I am doing wrong .

if ( charInString("\000d", str) )
out.print( "I have found a Carriage return" );

public boolean charInString(String c, String s)
{
for (int i = 0; i < s.length(); i++)
{ if (String.valueOf(s.charAt(i)) == c) return true;
}
return false;
}
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried doing something like using:

but the problem with this was that I still needed to know what platform I was running on. Since unix, windows, mac all use different control charactors.
I finally got my code to work but it is hardcoded for unix.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

0x0D = carriage return characters
0x0A = line feed
Rene
[ October 30, 2002: Message edited by: Rene Larsen ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is that what you were thinking of?
 
Manuel Paco
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, but my code still does not work.
(I run Windows 2000)
I am using String that I got from JTextArea
and I still can't find any carriage return in my string even it is there.
I've tried everything you advised.
Do you have any more ideas?
 
Manuel Paco
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to mention that the carriage return was
made by
out.println("");
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ya, that looks good. Thanks.
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use .equals() not == to compare two strings.
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And actually, if you want to search for one string within another, look at the String.indexOf() method.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manuel,
can you please post your current code and a simple testcase which fails but you want to pass? Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic