Skip to content

Instantly share code, notes, and snippets.

@twobob
Created August 20, 2021 18:29
Show Gist options
  • Save twobob/76777f6f1ab1fb35015670863cd7405c to your computer and use it in GitHub Desktop.
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
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');
}
}
}
@twobob
Copy link
Author

twobob commented Aug 20, 2021

consider
UnityEngine.Random.InitState((int)System.DateTime.Now.Ticks); or similar

This is just an example "Random" - and the default OOTB is not a very random one used improperly. feel free to replace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment