471,337 Members | 867 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

how to convert string into integer in c#

Bob
Hi,
How can i convert each character of the following string to the
integer value's.
"Hello World"
Jun 27 '08 #1
6 1737
foreach (char c in "Hello World")
{
Console.WriteLine((int)c);
}

Marc
Jun 27 '08 #2
Bob
On Jun 5, 12:23 pm, Marc Gravell <marc.grav...@gmail.comwrote:
foreach (char c in "Hello World")
{
Console.WriteLine((int)c);
}

Marc
Didn't know, it was that simple.
Thanks, it worked.
Jun 27 '08 #3
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.

On Jun 5, 6:52*am, Bob <t2ch...@yahoo.comwrote:
On Jun 5, 12:23 pm, Marc Gravell <marc.grav...@gmail.comwrote:
* * * * *foreach (char c in "Hello World")
* * * * *{
* * * * * * *Console.WriteLine((int)c);
* * * * *}
Marc

Didn't know, it was that simple.
Thanks, it worked.
Jun 27 '08 #4
Bob
On Jun 5, 3:16 pm, qglyirnyf...@mailinator.com wrote:
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.

On Jun 5, 6:52 am, Bob <t2ch...@yahoo.comwrote:
On Jun 5, 12:23 pm, Marc Gravell <marc.grav...@gmail.comwrote:
foreach (char c in "Hello World")
{
Console.WriteLine((int)c);
}
Marc
Didn't know, it was that simple.
Thanks, it worked.
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
Jun 27 '08 #5
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
On Jun 5, 10:28 am, Bob <t2ch...@yahoo.comwrote:
On Jun 5, 3:16 pm, qglyirnyf...@mailinator.com wrote:
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.
On Jun 5, 6:52 am, Bob <t2ch...@yahoo.comwrote:
On Jun 5, 12:23 pm, Marc Gravell <marc.grav...@gmail.comwrote:
foreach (char c in "Hello World")
{
Console.WriteLine((int)c);
}
Marc
Didn't know, it was that simple.
Thanks, it worked.

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
Jun 27 '08 #6
Bob
On Jun 6, 9:26 pm, jake <jakedim...@gmail.comwrote:
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

On Jun 5, 10:28 am, Bob <t2ch...@yahoo.comwrote:
On Jun 5, 3:16 pm, qglyirnyf...@mailinator.com wrote:
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.
On Jun 5, 6:52 am, Bob <t2ch...@yahoo.comwrote:
On Jun 5, 12:23 pm, Marc Gravell <marc.grav...@gmail.comwrote:
foreach (char c in "Hello World")
{
Console.WriteLine((int)c);
}
Marc
Didn't know, it was that simple.
Thanks, it worked.
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
Thanks Jack. It is much clearer like this.
Bob
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by IamZadok | last post: by
3 posts views Thread by Convert TextBox.Text to Int32 Problem | last post: by
8 posts views Thread by Carlos | last post: by
5 posts views Thread by Mika M | last post: by
14 posts views Thread by Drew | last post: by
20 posts views Thread by Niyazi | last post: by
3 posts views Thread by priyanka | last post: by
7 posts views Thread by elliotng.ee | last post: by

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.