fodev.net

FOnline Development => General Discussion => Topic started by: Mr Feltzer on September 08, 2013, 08:23:21 am

Title: Reading from a file to return a string[] array
Post by: Mr Feltzer 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.
Title: Re: Reading from a file to return a string[] array
Post by: k3tamina 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')
Title: Re: Reading from a file to return a string[] array
Post by: Mr Feltzer 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.
Title: Re: Reading from a file to return a string[] array
Post by: k3tamina 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.
Title: Re: Reading from a file to return a string[] array
Post by: Lidae 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.
Title: Re: Reading from a file to return a string[] array
Post by: Mr Feltzer 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.