Miscellaneous text in a string?

I was wondering how to have an if statement that could know if a certain part of a string doesn’t matter. For example, if I have this script:

var txt : String;

function Start () {
if(txt == "I am"+anything){
print("Hello");
}
}

I would want to replace where it says “anything” with something that would allow the script to ignore whatever comes after “I am”. If someone were to type in “I am Sam”, “I am Lisa”, “I am Bill”, etc., it would would always print(“Hello”). Is there a way to do this?

if (txt.Startswith(“I am”))

1 Like

Do you happen to know a way to save whatever “anything” would be as a variable?

Take a look at the string class reference from the MSDN. It has a list of the string manipulation functions you want.

anything = txt.Remove(0,4)

if (string.Contains("aSubsetOfMyText"))
    // do stuff

Cheers

1 Like

Thanks to everyone for your help. It wasn’t exactly what I was looking for, but I’ve founds ways to make it work with what you’ve all said. If anyone knows how to make “anything” act kind of like “%s” as used in Python, that’s really what I was trying to find out. Like I said, I’ve found ways to work around this, so this isn’t something that I desperately need.

string name = "John";
string formated = string.Format("Hello {0}.",  name);