CustomString Starts with and Ends with
bi3mer opened this issue · 0 comments
bi3mer commented
Add these string extension methods and include a link to https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity5.html in each function comments to explain why it is added.
Please update the bracketing style of this
public static bool CustomEndsWith(string a, string b) {
int ap = a.Length - 1;
int bp = b.Length - 1;
while (ap >= 0 && bp >= 0 && a [ap] == b [bp]) {
--ap;
--bp;
}
return (bp < 0 && a.Length >= b.Length) || (ap < 0 && b.Length >= a.Length);
}
public static bool CustomStartsWith(string a, string b) {
int aLen = a.Length;
int bLen = b.Length;
int ap = 0; int bp = 0;
while (ap < aLen && bp < bLen && a [ap] == b [bp]) {
++ap;
++bp;
}
return (bp == bLen && aLen >= bLen) || (ap == aLen && bLen >= aLen);
}