String class for string operations
Notes:
I. C# String class for string operations: [Starts at: 00min:00sec]
string is a sequence or array of unicode characters.
Unicode is a 16 bit character set.
string class contains common properties and methods used to work with strings.
Example Code:
using UnityEngine;
public class StringDemo : MonoBehaviour {
void Start () {
string myName = "Unity Game Engine";
Debug.Log (myName); // Unity Game Engine
Debug.Log(myName.Length); // 17
Debug.Log(myName.ToUpper()); // UNITY GAME ENGINE
Debug.Log(myName.ToLower()); // unity game engine
Debug.Log(myName.StartsWith("Unity")); // True
Debug.Log(myName.EndsWith("Engine")); // True
Debug.Log(myName.Contains("C#")); // False
// -1 if given parameter comes after in the dictionary
Debug.Log(myName.CompareTo("Unity Lame Engine")); // -1
// 0 if given parameter is same
Debug.Log(myName.CompareTo("Unity Game Engine")); // 0
// 1 if given parameter comes before in the dictionary
Debug.Log(myName.CompareTo("Unity Came Engine")); // 1
Debug.Log(myName.Equals("Unity Game Engine")); // True
// strings follow 0 based indexing
// syntax: string Remove(index, # of characters to remove)
Debug.Log(myName.Remove(6,4)); // Unity Engine
Debug.Log(myName.IndexOf('U')); // 0
Debug.Log ("Sum of " + 22 + " and " + 22 + " is = " + 44);
Debug.Log (string.Format ("Sum of {0} and {1} is= {2}", 22, 22, 44));
}
}
Note:
Use Equals method to check whether 2 strings are same or not
Use CompareTo method to check the chronological order in dictionary