Hi,
I'm trying to code a tile engine for a game a couple friends and I are making. The main speed bump that I've run into is converting a string, which the contents are only integers(from a text file), into a integer array.

How would I go about this?

Thanks in advance,
EpicAsian

Hi Epic Asian

Do you have an example of the string contents?

Cam

Here is an example of the text file contents:
0002 0002 0002 0002 0002 0002 0002 0002 0002 0002 0002 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

~EpicAsian

Sure, consider this example.

string input = "0008 0006 0007 0005 0003 0000 0009";

int[] array = input.Split().Select(s => int.Parse(s)).ToArray();

foreach (int i in array)
    Console.WriteLine(i);

okay let me try this

Read the file in as a string
Then this should work

public int [] convertString (string input)
 {
  char [] temp = input.ToCharArray();
  int [] temp2 = new int [temp.Length];
  
  for(int i = 0; i < temp.Length; i++)
   {
    temp2[i] = (int) temp[i];
   }
  return temps
 }

The for loop you might want to use the method below if the one above doesn't work

temp2[i] = Convert.ToInt32(temp[i]);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.