Help with end-of-line characters

P

Programmer

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?
 
J

Jon Skeet [C# MVP]

Programmer said:
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/strings.html#debugger for a
suggestion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top