Working with Strings [solved]

I am totally lost here. Is there any documentation I could dig through what sort of String operations are at hand?

Here is my Problem:

var myString: String = "asdXXXasd";

So how can I put the XXX in a new string?

I know it’s a stupid problem but Strings always hit you when least expected.

Im not sure what exactly it is you are trying to do, but Unity uses Mono (an implementation of .NET framework) for all the ‘generic’ non-api specific operations like string, file I/O, streams etc. So the place to look for info on string functions would be Mono/.NET reference:
http://www.go-mono.com/docs/monodoc.ashx?link=T%3ASystem.String

Thanks for the reply. Those docs are so weird, way above my level, I love the unity docs, they are way more understandable :slight_smile:

Anyway, I want to search the string for the first “asd” encounter and then spit out the next 3 characters in a new string, that’s it.

Agreed, but if you use low bandwidth mode for the MSDN docs, they become quite a bit more comprehensible (from a visual standpoint anyway).

–Eric

I’m kinda new to Unity also so my answer might be off the wall but… does Unity/Mono support regular expressions? You could do some sort of string matching using regex to find a match for the first 3 chars then a string maniulation to grab chars 4-6 of the string if there is a match…

Use String.IndexOf to find the first occurrence of the delimiter, then use String.Substring to get the characters you want:-

var indexPos: int = myString.IndexOf("asd");
var excerpt: string = myString.Substring(indexPos + 3, 3);

Sweet, works like a charm. Thanks everybody.
Here the final code I used. Just added the String.Length to keep it more dynamic.

var myString: String = "asdXXXasd";
var indexPos: int = myString.IndexOf("asd");
var excerpt: string = myString.Substring(indexPos + myString.Length, 3);

Why yes it does: http://www.unifycommunity.com/wiki/index.php?title=SimpleRegex

While you’re there, you might notice that the wiki has tons of useful scripts for common things like string parsing.

similarly you could have done this a little simpler - just by saying

string myString = “I am a string.” ;
string newString = myString.Substring(7);
Debug.Log(newString);

This code would start your new string at the 7th character of the original
string and would print -
string.