Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to convert string into integer in c#

0 views
Skip to first unread message

Bob

unread,
Jun 5, 2008, 7:08:28 AM6/5/08
to
Hi,
How can i convert each character of the following string to the
integer value's.
"Hello World"

Marc Gravell

unread,
Jun 5, 2008, 7:23:47 AM6/5/08
to
foreach (char c in "Hello World")
{
Console.WriteLine((int)c);
}

Marc

Bob

unread,
Jun 5, 2008, 7:52:38 AM6/5/08
to

Didn't know, it was that simple.
Thanks, it worked.

qglyir...@mailinator.com

unread,
Jun 5, 2008, 10:16:17 AM6/5/08
to
Bob,

If you don’t mind me asking. What is the purpose of you converting
these values to ints?

The reason why I ask is because you have to remember that the values
that you are converting are Unicode (UTF-16) values. There may be
times when you hit surrogate pair values and a simple conversion to
int won’t do what you expect.

If you are dealing with ASCII rage values then you should be fine.

It’s been a while since the last time I messed around with this
Unicode stuff so someone correct me if I am wrong!

Thaks
Rene.

Bob

unread,
Jun 5, 2008, 10:28:42 AM6/5/08
to

Rene,
I am a student. And these are my first steps. Just trying to walk. It
is part of a question. Now i have to figure out how to discard the
space and add the integer values.
But i think there are some things i should do on my own.
I understand what Marc explained. I saw on the internet and in books
that there is an option to do the same with Parse. But i did not
understand that.
Thanks
Bob

jake

unread,
Jun 6, 2008, 4:26:21 PM6/6/08
to
Bob,
(int)'1' ----> returns the ascii value of the character '1', which is
49
int.Parse("1") -----> returns the integer value of "1", which is 1
Hope this helps.
jake

Bob

unread,
Jun 8, 2008, 8:21:07 PM6/8/08
to

Thanks Jack. It is much clearer like this.
Bob

0 new messages