Author Topic: Reading from a file to return a string[] array  (Read 4601 times)

Offline Mr Feltzer

  • FOnline: Australia
    • The Core Gaming Australia's Website
Reading from a file to return a string[] array
« on: September 08, 2013, 08:23:21 am »
Hello, I have been working on a new bunch of systems and the documentation on the file reader is horrible.

IS there ANY way to read from a file and return every Line as a string within an Array?

Thanks lads, Good day.
Founder of Fallout Online Australia

Re: Reading from a file to return a string[] array
« Reply #1 on: September 08, 2013, 09:57:20 pm »
In C# you can read the entire contents of the file in a string, then split the string using a delimiter ('\n')

Offline Mr Feltzer

  • FOnline: Australia
    • The Core Gaming Australia's Website
Re: Reading from a file to return a string[] array
« Reply #2 on: September 09, 2013, 08:13:30 am »
Ah yes. Good Thinking haha

Edit:
Bastard Error my friend.
Code: [Select]
string filestring;
if(filestring[i] == "\n") // This returns Error: "No conversion from 'string@&' to 'uint' available." Even though I am simply gathering a string with an index. @_@

Any ideas? I have worked with strings before and have never seen this issue.
« Last Edit: September 09, 2013, 08:38:28 am by Mr Feltzer »
Founder of Fallout Online Australia

Re: Reading from a file to return a string[] array
« Reply #3 on: September 09, 2013, 07:33:00 pm »
Just read what the error says, you're comparing a uint (wide char filestring[ i ]) with a string ("\n"), it's like comparing carrots and apples.
« Last Edit: September 10, 2013, 12:16:05 am by k3tamina »

Re: Reading from a file to return a string[] array
« Reply #4 on: September 09, 2013, 08:57:41 pm »
You can also split strings in angelcode using one of these:

Code: [Select]
string[]  split (const string& in str, const string& in delimiter)
  Splits the string into an array of substrings.
 
string[]  splitEx (const string& in str, const string& in delimiter)
  Splits the specified string by string, using the specified separator.

Offline Mr Feltzer

  • FOnline: Australia
    • The Core Gaming Australia's Website
Re: Reading from a file to return a string[] array
« Reply #5 on: September 10, 2013, 08:58:43 am »
You can also split strings in angelcode using one of these:

Code: [Select]
string[]  split (const string& in str, const string& in delimiter)
  Splits the string into an array of substrings.
 
string[]  splitEx (const string& in str, const string& in delimiter)
  Splits the specified string by string, using the specified separator.


Excellent! that did the trick!

@k3tamina
In all my previous experiences with C#, an Index on a string locates a char or part of the string.
example
string lestring = "hax";
lestring[0] would be h

Obviously Angel has changed a tad more than I expected.
Founder of Fallout Online Australia