1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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)
- {
- 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);
- }
- }
- }
|