Text parsing

How can i parse a .txt file with unity iphone?
I already did a search on forums and searched the script reference.
I never needed that before and feel like the uber-n00b now that I am asking for such basic functions. :sweat_smile:

Vic, can I ask what you are doing with this text file?

I’m using text files for data input into GUI Text fields, and they work as expected in regular Unity.

I have a text asset in my project (Assets/My Assets/Text Assets) and load them by dragging the .txt asset onto an exposed variable in the inspector. With function Start();, I bring the text asset into the game.

I assume you could load your variable the same way.

Now parsing that for game play data, I have not done, but the text asset should work fine, and I’d assume that parsing it would be the same as in Unity.

//  New Variables
var helpTextAsset : TextAsset;          //     Exposes a slot in the inspector
private var helpText : String;

function Start() {
	helpText = helpTextAsset.text;
}

function OnGUI {
		GUI.Label (Rect(0, 0, (Screen.width * 0.75), helpWindowLength), helpText, "helptext");
}

Thanks! But i already found out how to load a text asset from the script reference.

My question was not clear enough - my problem is to find out how to find a letter(s) in a string.

you can use full csharp string functions, even from javascript (not sure, you might have to add the line ‘import System;’ at the beginning of your javascript file.

http://en.csharp-online.net/Manipulating_Strings_in_CSharp

While I’m procrastinating:

googled some stuff on the site…
(parsing text site:forum.unity3d.com - Google Search)

(parsing text site:forum.unity3d.com)

http://forum.unity3d.com/viewtopic.php?p=12103

http://forum.unity3d.com/viewtopic.php?t=5531

what I do in my current project is this:

var stringArray = rawData.Split(char.Parse("|"));

I get data via www from a php-script that formats the data like this: “Name1|Name2|Name3|Name4” and the finished stringArray will then contain [Name1, Name2, Name3, Name4]…

if you need more string functions check out any list of String Functions