Jak usunąć wszystkie białe spacje z początku lub końca łańcucha?
Jak usunąć wszystkie białe spacje z początku i końca łańcucha?
Like so:
"hello"
zwroty "hello"
"hello "
zwroty "hello"
" hello "
zwroty "hello"
" hello world "
returns "hello world"
6 answers
String.Trim()
przycina wszystkie białe spacje od początku i końca łańcucha:
" A String ".Trim() -> "A String"
String.TrimStart()
przycina wszystkie białe spacje od początku łańcucha:
" A String ".TrimStart() -> "A String "
String.TrimEnd()
przycina wszystkie białe spacje od końca łańcucha:
" A String ".TrimEnd() -> " A String"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-20 14:12:17
Spójrz na Trim()
który zwraca nowy łańcuch znaków z usuniętymi białymi spacjami od początku i końca łańcucha, który jest wywoływany.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-08-01 12:09:50
string a = " Hello ";
string trimmed = a.Trim();
trimmed
jest teraz "Hello"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-08-01 12:10:10
Użyj funkcji String.Trim()
.
string foo = " hello ";
string bar = foo.Trim();
Console.WriteLine(bar); // writes "hello"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-08-01 12:09:59
Użyj metody String.Trim
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-08-01 12:22:37
String.Trim()
usuwa wszystkie białe znaki z początku i końca łańcucha.
Aby usunąć białe znaki wewnątrz łańcucha lub znormalizować białe znaki, użyj wyrażenia regularnego.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-08-01 12:10:30