Skip to content

Instantly share code, notes, and snippets.

@phi-jp phi-jp/StringExtensions.cs
Last active Aug 29, 2015

Embed
What would you like to do?
string extension
/*
* Copyright (c) 2014 @phi_jp
*/
using System;
namespace tm.Extensions {
public static class StringExtensions {
public static string Coloring(this string str, string color) {
return string.Format ("<color={0}>{1}</color>", color, str);
}
public static string Red(this string str) {
return str.Coloring ("red");
}
public static string Green(this string str) {
return str.Coloring ("green");
}
public static string Blue(this string str) {
return str.Coloring ("blue");
}
public static string Resize(this string str, int size) {
return string.Format ("<size={0}>{1}</size>", size, str);
}
public static string Medium(this string str) {
return str.Resize (11);
}
public static string Small(this string str) {
return str.Resize (9);
}
public static string Large(this string str) {
return str.Resize (16);
}
public static string Bold(this string str) {
return string.Format ("<b>{0}</b>", str);
}
public static string Italic(this string str) {
return string.Format ("<i>{0}</i>", str);
}
}
}
using UnityEngine;
using System.Collections;
using tm.Extensions;
public class Deco : MonoBehaviour {
// Use this for initialization
void Start () {
// color
Debug.Log ("Hello, world(Red)".Red ());
Debug.Log ("Hello, world(Green)".Green ());
Debug.Log ("Hello, world(Blue)".Blue ());
// size
Debug.Log ("Hello, world(Medium)".Medium());
Debug.Log ("Hello, world(Small)".Small());
Debug.Log ("Hello, world(Large)".Large());
// style
Debug.Log ("Hello, world(Bold)".Bold());
Debug.Log ("Hello, world(Italic)".Italic());
}
void OnGUI() {
GUI.Label (new Rect(10, 10, 100, 100), "<color=red>Hello, world!</color>");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.