1. Regular Expression: system. Text. regularexpressions. RegEx. Replace (STR, "([] + )","")-- STR is the input or string to be checked.
2. Use the string's built-in replace method: Str. Replace ("","")------------- STR is the input or string to be checked.
3. Because the ASCII value of space is 32, when removing all spaces in the string, you only need to cyclically access all characters in the string and determine whether their ASCII value is 32. The key code to remove all spaces in the string is as follows:
- Charenumerator cenumerator = textbox1.text. getenumerator ();
- While (cenumerator. movenext ())
- {
- Byte [] array = new byte [1];
- Array = system. Text. encoding. ASCII. getbytes (cenumerator. Current. tostring ());
- Int asciicode = (short) (array [0]);
- If (asciicode! = 32)
- {
- Textbox2.text + = cenumerator. Current. tostring ();
- }
- }
The three methods can only remove halfwidth spaces, but not fullwidth spaces.