String length

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

I have a string:(actually its a line turned into a string)
"30 40 04 40 FF 3F 31 40 00 39 B0 12 4E 40 B0 12'

in c strlen() gives me 49
but c# :
LinetoString = infile.ReadLine();
linelen= LinetoString.Length;

Gives me 47.(Sounds more accurate)

Both doc say the number is before any terminating Chars.

Any help.

Can I "pad" it?

Thanks
Mike
 
|I have a string:(actually its a line turned into a string)
| "30 40 04 40 FF 3F 31 40 00 39 B0 12 4E 40 B0 12'
|
| in c strlen() gives me 49
| but c# :
| LinetoString = infile.ReadLine();
| linelen= LinetoString.Length;
|
| Gives me 47.(Sounds more accurate)
|
| Both doc say the number is before any terminating Chars.
|
| Any help.
|
| Can I "pad" it?
|
| Thanks
| Mike
|

C# is correct, the string as it looks like, has 47 characters, guess in C
you are reading from a file and the string include CR/LF or LF/CR at the
end, while in C# you just declared the string.
Not sure what you mean with truncate, truncate what?

Willy.
 
Hi Mike,

The difference in length might come from C# using unicode characters in
strings. Representing anything but text data inside a string is a bad
idea and is bound to cause errors.
 
No, the difference is only 2 characters, probably due to a cr/lf sequence in
the C string. Anyway, you can't put anything but characters in a string and
the string the OP posted is a valid string ,unicode or not.

Willy.

Hi Mike,

The difference in length might come from C# using unicode characters in
strings. Representing anything but text data inside a string is a bad
idea and is bound to cause errors.
 
Hello,
So how do I insert the cr\lf into my string, but as hex not ascii.
In my c program the string looks like this:(In the IDE)
strdata = "30 40 04 40 FF 3F 31 40 00 39 B0 12 4E 40 B0 12 (Little
Square)(Little Square)".
I'm not sure if this is correct but I do need to put them in.Since they
are not represented as charecters in my code, I dont know if this would
work.

Thanks
Mike
"
 
| Hello,
| So how do I insert the cr\lf into my string, but as hex not ascii.
| In my c program the string looks like this:(In the IDE)
| strdata = "30 40 04 40 FF 3F 31 40 00 39 B0 12 4E 40 B0 12 (Little
| Square)(Little Square)".
| I'm not sure if this is correct but I do need to put them in.Since they
| are not represented as charecters in my code, I dont know if this would
| work.
|

strdata = "......." + Environment.Environment.NewLine;
or
strdata = "......." + '\r' + '\n'
or
.... (to be filled by YOU).

But honestly I fail to see why you need these in the string.

Willy.
 

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

Back
Top