2 Replies - 895 Views - Last Post: 08 January 2008 - 09:10 AM Rate Topic: -----

#1 rareseu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-December 07

String conversion driving me nuts

Posted 08 January 2008 - 06:20 AM

Hello ppl ! i'm trying to read the values of signal out of a .txt file so that i can draw the signal in a picturebox, but i'm running into a very annoying problem when i try to convert a string to integer, here are the bits of code to make it easier to understand :

//variables that i'm using
private string[] info;
private int[] signalValues;



   
//read from file and take out white spaces	   
info = sourceFile.ReadToEnd().Split(' '); 

//converting the info to integer
for (int i = 0; i <= info.Length; i++)
   signalValues[i] = Convert.ToInt32(info[i]);



and i'm getting a "Input string not in a correct format" unhandled expection, the numbers in the file are small (3 digits max), please tell me what i'm doing wrong

Is This A Good Question/Topic? 0
  • +

Replies To: String conversion driving me nuts

#2 qdoom  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 82
  • Joined: 31-August 06

Re: String conversion driving me nuts

Posted 08 January 2008 - 07:56 AM

Welcome to dream.in.code!

1. <= means, that it will do the loop one too many times. <= operator returns true, if the first operand is less than or equal to the second. You should get "IndexOutOfRangeException". It should be:

for (int i = 0; i < info.Length; i++)
   signalValues[i] = Convert.ToInt32(info[i]);


2. if your numbers are not in one line, the program will not split the newline for you. That's why you could be getting "Input string not in a correct format" exception.

info = sourceFile.ReadToEnd().Split(' ', '\n');


Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#3 rareseu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-December 07

Re: String conversion driving me nuts

Posted 08 January 2008 - 09:10 AM

thank you it did help :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1