「Unity/Csharp/文字操作」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→分割(改行)) |
|||
| 行30: | 行30: | ||
==大文字を小文字へ== | ==大文字を小文字へ== | ||
name.ToLower(); | name.ToLower(); | ||
| + | |||
| + | ==文字列検索== | ||
| + | .区切りの一番最後の文字列を取得(jp.co.example.hogehogeのhogehogeを取得する) | ||
| + | int startindex = className.LastIndexOf('.') + 1; | ||
| + | string adName = className.Substring(startindex, className.Length - startindex); | ||
2018年6月29日 (金) 19:06時点における版
文字の長さ
String name = "abcdef"; name.Length; // 6
文字の切り取り
String name = "abcdef"; name = name.Substring (name.Length - 2, 2); // ef
検索
if (name.IndexOf("検索文字列") == -1) {
// no hit
} else {
// hit
}
分割
name = "1234:2345";
string[] names = name.Split(":"[0]);
Debug.Log(names[0]); // 1234
Debug.Log(names[1]); // 2345
分割(改行)
using System;
string str = "test\r\ntest\r\ntest";
string[] lines = str.Split(new []{"\r\n"}, StringSplitOptions.None);
小文字を大文字へ
name.ToUpper();
大文字を小文字へ
name.ToLower();
文字列検索
.区切りの一番最後の文字列を取得(jp.co.example.hogehogeのhogehogeを取得する)
int startindex = className.LastIndexOf('.') + 1;
string adName = className.Substring(startindex, className.Length - startindex);
