471,350 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Help with end-of-line characters

I have this following code:
x= tempStr.IndexOf((char)13, 0);
The string tempSTR = "
Heading"
Notice that their is a Carriage Return and/or line feed before the
stirng value of "heading?" What I was wanting to do with this code is
for the variable x to equal to location of the first carriage
return/line feed/new line caracter (ASCII 13 or 10 values). But it
seems that when I run this the value of x= 9 instead of 1 why is this?
Bascially I am porting a VBA program into a C# program for a word
automation application I wrote. In VBA this is what I had for this
function:
x = InStr(1, tempStr, chr(13))
In VBA x = 1 not 9. Does anyone know of a whay to make the c#
expression equal 1 instead of 9?

Feb 9 '06 #1
1 7325
Programmer <mr********@gmail.com> wrote:
I have this following code:
x= tempStr.IndexOf((char)13, 0);
Just a quick hint - that would be more easily understood if it were
written as
x = tempStr.IndexOf ('\r');
The string tempSTR = "
Heading"
How sure are you that there are no leading spaces?
Notice that their is a Carriage Return and/or line feed before the
stirng value of "heading?" What I was wanting to do with this code is
for the variable x to equal to location of the first carriage
return/line feed/new line caracter (ASCII 13 or 10 values). But it
seems that when I run this the value of x= 9 instead of 1 why is this?


Presumably because there are other characters before the carriage
return/line feed.

See http://www.pobox.com/~skeet/csharp/s....html#debugger for a
suggestion.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mike | last post: by
1 post views Thread by Mike | last post: by
13 posts views Thread by Chua Wen Ching | last post: by
3 posts views Thread by Marek | last post: by
2 posts views Thread by Brian | last post: by
6 posts views Thread by momo | last post: by
13 posts views Thread by Apostle | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.