Created
August 20, 2021 18:29
-
-
Save twobob/76777f6f1ab1fb35015670863cd7405c to your computer and use it in GitHub Desktop.
Stylise a string by doing multiple replacements at once and using extenstion methods. Unity3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Linq; | |
namespace ExtensionMethods | |
{ | |
static class ElevenStringHelpers | |
{ | |
// called as shown below | |
public static string ReplaceAll(this string seed, char[] chars, char replacementCharacter) | |
{ | |
return chars.Aggregate(seed, (str, cItem) => str.Replace(cItem, replacementCharacter)); | |
} | |
//called like | |
// using ExtensionMethods; | |
// "whatever".Elvenize(); | |
public static string Elvenize(this string seed) | |
{ | |
char[] firstflip = new char[] { 'i', 'o' }; | |
char[] secondflip = new char[] { 'e', 'u' }; | |
return seed | |
.ReplaceAll(firstflip, (Random.value > 0.5f) ? 'e' : 'y') | |
.ReplaceAll(secondflip, (Random.value > 0.5f) ? 'a' : 'o'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
consider
UnityEngine.Random.InitState((int)System.DateTime.Now.Ticks);
or similarThis is just an example "Random" - and the default OOTB is not a very random one used improperly. feel free to replace