File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes carriage return Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "carriage return" Watch "carriage return" New topic
Author

carriage return

Manuel Paco
Ranch Hand

Joined: Sep 23, 2001
Posts: 58
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

Joined: Mar 16, 2001
Posts: 986

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.


Please ignore post, I have no idea what I am talking about.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try this:

0x0D = carriage return characters
0x0A = line feed
Rene
[ October 30, 2002: Message edited by: Rene Larsen ]

Regards, Rene Larsen
Dropbox Invite
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112

Is that what you were thinking of?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Manuel Paco
Ranch Hand

Joined: Sep 23, 2001
Posts: 58
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

Joined: Sep 23, 2001
Posts: 58
I forgot to mention that the carriage return was
made by
out.println("");
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986


Ya, that looks good. Thanks.
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
Use .equals() not == to compare two strings.
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
And actually, if you want to search for one string within another, look at the String.indexOf() method.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Manuel,
can you please post your current code and a simple testcase which fails but you want to pass? Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: carriage return