123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- namespace textUtility
- {
- using System;
- using System.Collections;
- using System.Collections.Generic;
-
- using UnityEngine;
-
- public static class StringExtension
- {
- public static bool IsNullOrEmpty(this string str)
- {
- return string.IsNullOrEmpty(str);
- }
- public static string Unwrap(this string str)
- {
- int leftIndex = str.IndexOf('(') + 1;
- int rightIndex = str.LastIndexOf(')') - 1;
- return str.Substring(leftIndex, rightIndex - leftIndex + 1);
- }
- public static string Replace(this string str, int index, int length, string newStr)
- {
- str = str.Remove(index, length);
- str = str.Insert(index, newStr);
- return str;
- }
- public static string Between(this string str, int startIndex, int endIndex)
- {
- if (startIndex > endIndex)
- {
- throw new Exception();
- }
- else if (startIndex == endIndex)
- {
- return str[startIndex].ToString();
- }
- else
- {
- return str.Substring(startIndex, endIndex - startIndex + 1);
- }
- }
- public static List<string> ReplaceAll(this List<string> strings, string oldValue, string newValue)
- {
- List<string> results = new List<string>();
- for (int i = 0; i < strings.Count; i++)
- {
- results.Add(strings[i].Replace(oldValue, newValue));
- }
- return results;
- }
- }
- }
|