見た目ではわからない空白を削除したい。

いつも大変お世話になっております。
Excel上の文字列を取得する際に、スペースを取り除いてもまだ空白が残っています。

変数 = 変数.ToString().Replace(" ", string.Empty)

としたところ、
“message”: " 9911000" と表示され、

下記のエラーが生じます。
「 “message”: “代入: Conversion from string "???9911000" to type ‘Double’ is not valid.”,」

お気づきの点ありましたらご教授ください。

@kiki1

変数 = 変数.ToString().Replace(" ", String.Empty).Trim()

Hi @kiki1

Can you try the below:

変数 = CDbl(変数).ToString.Replace(" ",String.Empty).Trim()

Hope it helps!!
Regards

Hi @kiki1

Can you try the below

YourVar = System.Text.RegularExpressions.Regex.Replace(YourVar.ToString(), "[^0-9]", "").Trim()

Cheers!!

Thank you for your kindness :relieved:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.