12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using UnityEngine;
- using System;
- using System.Collections;
- public static class ExtensionString
- {
- public static T ToEnum<T>(this string str)
- {
- return (T)Enum.Parse(typeof(T), str);
- }
- public static string Remove(this string str, int startIndex, int endIndex, bool empty)
- {
- if (startIndex > endIndex)
- {
- throw new Exception();
- }
- return str.Remove(startIndex, endIndex - startIndex + 1);
- }
- public static string Replace(this string str, int startIndex, int endIndex, string newStr)
- {
- if (startIndex > endIndex)
- {
- throw new Exception();
- }
- str = str.Remove(startIndex, endIndex - startIndex + 1);
- str = str.Insert(startIndex, newStr);
- return str;
- }
- public static string Between(this string str, int startIndex, int endIndex)
- {
- if (startIndex > endIndex)
- {
- return "";
- }
- else if (startIndex == endIndex)
- {
- return str[startIndex].ToString();
- }
- else
- {
- return str.Substring(startIndex, endIndex - startIndex + 1);
- }
- }
- }
|