- Home /
What can I use to find part of a phrase in a string?
I'm trying to set up a commands system, but I'm not sure how I would find if the string has a slash at the beginning. Similar to some programming languages (I'm referring to Batch files or MS DOS in this lol), you can use the asterisk/star symbol (*) to substitute portions of variables. So I guess what I'm looking for is something like this:
if (someString == "/*") {
Do some command code here
}
Because the if statement is only looking for if the user has a slash at the beginning, I couldn't really use Split. How would this work in C#?
I see you haven't ever accepted an answer or voted an answer to the questions you've asked. Please consider doing so if you used the answers in your implementation - it's Q&A etiquette :).
Answer by fendorio · Apr 20, 2014 at 03:22 AM
You could use a RegularExpression? Found in the below namespace:
using System.Text.RegularExpressions;
void Foo()
{
if(Regex.IsMatch(someString, "\*"))
{
//You have a match
}
}
Answer by Eric5h5 · Apr 20, 2014 at 03:51 AM
if (someString.StartsWith ("/")) {
By the way, look up string functions on $$anonymous$$SDN, since that's not really Unity-related.