473,394 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

String length

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

Sep 20 '06 #1
5 2847

"AMP" <am******@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
|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.


Sep 20 '06 #2
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.
On Wed, 20 Sep 2006 22:45:51 +0200, AMP <am******@gmail.comwrote:
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


--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 21 '06 #3

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.

"Morten Wennevik" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
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.
On Wed, 20 Sep 2006 22:45:51 +0200, AMP <am******@gmail.comwrote:
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


--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 21 '06 #4
AMP
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
"
Willy Denoyette [MVP] wrote:
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.

"Morten Wennevik" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
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.
On Wed, 20 Sep 2006 22:45:51 +0200, AMP <am******@gmail.comwrote:
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

--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 21 '06 #5

"AMP" <am******@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
| 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.
Sep 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mitchua | last post by:
Simplified a bit, I'm parsing HTML documents to get sentences e.g. my $html = get($URL); # remove all HTML TAGs...blah blah blah @sentences = split(/\./, $html)); then I'm trying to determine the...
18
by: Zygmunt Krynicki | last post by:
Hello I've browsed the FAQ but apparently it lacks any questions concenring wide character strings. I'd like to calculate the length of a multibyte string without converting the whole string. ...
2
by: Tom Dacon | last post by:
I'm raising an event in a component, using ISynchronizeInvoke.Invoke, and my event args object contains a string as one of its members. If the string is longer than 63 bytes, the Invoke call pulls...
8
by: Al Sav | last post by:
Hi, Which one of these below two is a better way to find out if the string is of zero length? string.Length == 0 or string.Length < 0 Alwin S.
10
by: A.M | last post by:
Hi, How can I use validation controls to check max length of string text boxes? Thanks, Alan
3
by: Sam | last post by:
I want to divide character into 2 section. Example, 200412 divided into 2004 in A block and 12 in B block. Please advise how to use left(string, length) or right(string, length) for above...
1
by: MattB | last post by:
Hi. I've got a vb.net/asp.net application that passes strings back a forth between a c++ COM object. We use simple tagging to designate what's what, and it's worked pretty well until now. We had...
3
by: ipellew | last post by:
Hi; Whats the maximum string length in Javascript. Is it the same across all the browsers? max_s_len = str.length // what the max number of chars we can have is str? Regards
5
by: gezerpunta | last post by:
Hi strlen does not return the correct value .I compared the filesize() and strlen byte size but they are not equal. I must find binary string length and it must be equal to filesize() thks.
6
by: csmith8933 | last post by:
I'm trying to loop until the string length is 0, deleting one character at a time. This doesnt work for obvious reasons I'm sure. string s; s = "0000011111"; while (s.length() 0) {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.