J'ai eu besoin de manipuler des chaînes de caractères et je me suis fait une liste de fonctions.
La problématique du JS Unity c'est qu'il est propre à lui-même et peu documenté
Je vous partage ma recherche pour les fonctions suivantes :
- Compare
Empty
IndexOf
Insert
Join
LastIndexOf
Length
PadLeft
PadRight
Replace
Remove
Split
Substring
ToLower
ToUpper
Trim
Code : Tout sélectionner
var strString : String = "Azerty-or-qwerty"; // String used in the examples
// Compare(,,)
if (String.Compare(strString, strString.ToLower())) print(strString + " == " + strString.ToLower()); else print(strString + " != " + strString.ToLower());
if (String.Compare(strString, strString.ToLower(), true)) print(strString + " == " + strString.ToLower()); else print(strString + " != " + strString.ToLower());
// Empty
if (strString.Empty) print("strString is Empty"); else print("strString is NOT Empty");
// IndexOf(), : Index base 0
print("IndexOf() : " + strString.IndexOf("r")); // => 3
print("IndexOf() : " + strString.IndexOf("r", 5)); // => 8
// Insert(,)
print("strString.Insert():" + strString.Insert(6, "Six")); // => "AzertySix-or-qwerty"
// Join(,)
var strArray = ["One", "Two", "Three"];
print("Join : " + String.Join("+", strArray)); // => "One+Two+Three"
// LastIndexOf(,) : Index base 0
print("lastIndexOf() : " + strString.LastIndexOf("r")); // => 13
print("lastIndexOf() : " + strString.LastIndexOf("r", 11)); // => 8
// Length
print("strString.Length : " + strString.Length); // => 16
// PadLeft()
print("Begin" + strString.PadLeft(20)); // => "Begin Azerty-or-qwerty"
// PadRight()
print(strString.PadRight(20) + "End"); // => "Azerty-or-qwerty End"
// Replace(,)
print(strString.Replace("or", "NOT")); // => "Azerty-NOT-qwerty"
print(strString.Replace("Xor", "NOT")); // => No change
// Remove(,)
print("Remove() : " + strString.Remove(6, 3)); // => "Azerty-qwerty"
// Split()
var strSplit = strString.Split("r"[0]);
var i : int;
for (i = 0; i < strSplit.Length; i++){
print (strSplit[i]); // => [0]:"Aze", [1]:"ty-o", [2]:"-qwe", [3]:"ty"
}
// Substring(,)
print(strString.Substring(0, 6)); // => "Azerty"
print(strString.Substring(7, 2)); // => "or"
// ToLower()
print(strString.ToLower()); // => "azerty-or-qwerty"
// ToUpper()
print(strString.ToUpper()); // => "AZERTY-OR-QWERTY"
// Trim()
print(" <-X-> ".Trim()); // => "<-X->"
// String to Char
print(strString[0]); // => A
Doc Mono System.String Members (Et il reste d'autres fonctions à visiter )
Doc Unify Community