Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字と数字を含む文字列があります。ここに例:
OG000134W4.11
これを取得するには、最初の文字と最初のゼロをすべて削除する必要があります。
134W4.11
また、最終的に取得するために、彼が遭遇する最初の文字から文字を切り取る必要があります。
134
複数の「トリム」でこれを行うことができることは知っていますが、それを行う効率的な方法があったかどうかを知りたいです。
ありがとう。
正規表現を使いたくない場合は、Linqがあなたの友達です
[Test] public void TrimTest() { var str = "OG000134W4.11"; var ret = str.SkipWhile(x => char.IsLetter(x) || x == '0').TakeWhile(x => !char.IsLetter(x)); Assert.AreEqual("134", ret); }