Is there any way to just check what the first letter of a string is in c#? i can't find anything that can help.
You can access chars of a string like arrays:
String s = "tada";
if (s[0] == 't'){
Debug.Log("tada");
}
C#:
String s = "tada";
Debug.Log("The first character of the string is: " + s.Substring(0, 1));
What the substring method does is retrieve a string within the string. The first parameter 0 is the starting index (starting position of the substring), and the number 1 is the amount of characters to grab.
var myString = "abc";
print (myString[0]);
slice the string http://www.swishtutor.com/s/0020.htm then compare the result with what you want
SARWAN
6
return (myString[0] >= ‘A’ && myString[0] <= ‘Z’) || (myString[0] >= ‘a’ && myString[0] <= ‘z’)
///
/// Replaces the first occurrence.
///
/// The source.
/// The find.
/// The replace.
///
public static string ReplaceFirstOccurrence(string Source, string Find, string Replace)
{
int Place = Source.IndexOf(Find);
string result = Source.Remove(Place, Find.Length).Insert(Place, Replace);
return result;
}
/// <summary>
/// Replaces the last occurrence.
/// </summary>
/// <param name="Source">The source.</param>
/// <param name="Find">The find.</param>
/// <param name="Replace">The replace.</param>
/// <returns></returns>
public static string ReplaceLastOccurrence(string Source, string Find, string Replace)
{
int Place = Source.LastIndexOf(Find);
string result = Source.Remove(Place, Find.Length).Insert(Place, Replace);
return result;
}