473,385 Members | 1,474 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,385 software developers and data experts.

Ascii code in C#

6
Hello!
Even i've read smth about this in this forums.. i still have problems with getting the ascii code of a character.

here is my problem

I have a string with characters. I have another int array in wich I have to put on every position the correspondent ascii code of first string's elements.

I've tried a few sollutions found here, but got errors :(

this is my latest attemp:

String sir;
int[] sirAux = new int[300];
for (int i = 0; i < 300; i++)
{
sirAux[i] = Convert.ToInt32(sir[i]);
}

and give the error: "Index was outside the bounds of the array."
//the error does not appear on compiling, but during running the application

please help :)
Sep 12 '07 #1
2 2215
Shashi Sadasivan
1,435 Expert 1GB
Hello!
Even i've read smth about this in this forums.. i still have problems with getting the ascii code of a character.

here is my problem

I have a string with characters. I have another int array in wich I have to put on every position the correspondent ascii code of first string's elements.

I've tried a few sollutions found here, but got errors :(

this is my latest attemp:

String sir;
int[] sirAux = new int[300];
for (int i = 0; i < 300; i++)
{
sirAux[i] = Convert.ToInt32(sir[i]);
}

and give the error: "Index was outside the bounds of the array."
//the error does not appear on compiling, but during running the application

please help :)
A little bit modification will help
Expand|Select|Wrap|Line Numbers
  1. String sir;
  2. int[] sirAux = new int[300];
  3. for (int i = 0; i < 300 && i < sir.Length; i++)
  4. {
  5.    sirAux[i] = Convert.ToInt32(sir[i]);
  6. }
  7.  
Wat is most probably happening is that your string is less than 300 charachters long.
you can also make the declration of sirAux to
Expand|Select|Wrap|Line Numbers
  1. int[] sirAux = new int[sir.Length];
And then you can remove the condition of i<300 from the for loop.

cheers
Sep 12 '07 #2
Maj
6
Thanks a lot!

You explanatin really helped me and I managed to finnish my application :)

Cheers, Maj
Sep 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

37
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be...
2
by: Martín Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program...
11
by: Kai Bohli | last post by:
Hi all ! I need to translate a string to Ascii and return a string again. The code below dosen't work for Ascii (Superset) codes above 127. Any help are greatly appreciated. protected...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
10
by: Mark Rae | last post by:
Hi, I'm in the process if converting the data out of an old DOS-based SunAccounts system (don't ask!) into SQL Server. The data has been sent to me as a collection of hundreds of SunAccounts...
9
by: pamelafluente | last post by:
I have found on the web a post with this useful way to convert (if possible) a ScanCode to Ascii. This is remarkably useful to filter keys under KeyDown/up event. My problem is that I am not...
31
by: Claude Yih | last post by:
Hi, everyone. I got a question. How can I identify whether a file is a binary file or an ascii text file? For instance, I wrote a piece of code and saved as "Test.c". I knew it was an ascii text...
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.