0

これが機能しない理由を誰か教えてください:

string txt = "+0°1,0'";
string degree = txt.TrimEnd('°');

この文字列で度数を分けようとしているのですが、このあと度数に残っているのはtxtの同じ内容です。

Visual Studio で C# を使用しています。

4

3 に答える 3

4

string.TrimEnd 末尾の char を削除します。あなたの例では、「°」は最後ではありません。

例えば ​​:

string txt = "+0°°°°";
string degree = txt.TrimEnd('°');
// degree => "+0"

「°」とそれに続くすべての文字を削除したい場合は、次のことができます。

string txt = "+0°1,0'";
string degree = txt.Remove(txt.IndexOf('°'));
// degree => "+0"
于 2020-08-19T11:24:44.507 に答える