/// <summary> /// スネークケースに変換する。 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string CamelToSnake(string str, bool isUpper = false) { var charList = new NList <char>(); foreach (var item in str) { charList.Add(item); } int index = 1; var target = new NList <char>(); for (int i = 0; i < charList.Count; i++) { var item = charList[i]; var nextItem = (charList.Count > i + 1)? charList[i + 1] : new char(); target.Add(item); if (!charList.IsLast(item) && abcUpperList.Contains(nextItem)) { target.Insert(index, '_'); index++; } index++; } var res = new string(target.ToArray()); return(isUpper ? res.ToUpper() : res.ToLower() ); }