String Problem

G

Guest

Hello!

I have two questions.

-I don't seem to be able to set string length in c#. It seems to be a
variable.

-when I am composing the body of an email in code, there is a "!" in the
string. I am assuming it has to do with the string length, hence I did this:

StringBuilder Body = new StringBuilder(10000);
Body.Append("<html>");
....
and then later:
mm.Body = body.ToString();

The result is exactly the same. I am still getting the exclamation mark
towards the end of the string.

Any clues are very welcome. Thank you!

-Bahman
 
H

Hans Kesting

Bahman said:
Hello!

I have two questions.

-I don't seem to be able to set string length in c#. It seems to be a
variable.

You can't "set" the length of a string, you don't need to "reserve space"
if that is what you are trying to do. The Length is the number of characters
in the string.
-when I am composing the body of an email in code, there is a "!" in
the string. I am assuming it has to do with the string length, hence
I did this:

StringBuilder Body = new StringBuilder(10000);
Body.Append("<html>");
...
and then later:
mm.Body = body.ToString();

The result is exactly the same. I am still getting the exclamation
mark towards the end of the string.

You will need to examine your code, there should be no characters added
automatically. By the way: how did you see that "!"? The safest way is to
print the string somehow. The watch window uses it's own rules to display
a string, which confuses a lot of people.

IIRC the maximum length of a string is Int32.MaxValue


By the way: if you are building a string (adding lots of fragments),
it is better to use the StringBuilder.
If you add string-fragments to a String, you are creating lots of
intermediate string-objects.
 

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

Similar Threads

Problem Splitting Text String 2
Java problem 1
Getchar() problem 8
Measuring a string of text 1
String and list error while running a Markov Chain 1
Google appscript 0
Error with server 3
Looking For Advice 1

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top