.trim()
-
When I test the String.Trim() function,my resource codes as follows: using System; using System.Collections.Generic; using System.Text; namespace Ch05Ex05 { class Program { static void Main(string[] args) { string myString = " This is a test. "; char[] separator = {' '}; char[] test ={ 'T', 'i' }; string[] myWords; myString = myString.Trim(test); // myWords = myString.Split(separator); foreach (char C in myString) { Console.WriteLine("{0}", C); } Console.ReadKey(); } } } The alphabet T and i should be removed ,but when I excuted my codes,It change nothing! Can you tell me why?
-
When I test the String.Trim() function,my resource codes as follows: using System; using System.Collections.Generic; using System.Text; namespace Ch05Ex05 { class Program { static void Main(string[] args) { string myString = " This is a test. "; char[] separator = {' '}; char[] test ={ 'T', 'i' }; string[] myWords; myString = myString.Trim(test); // myWords = myString.Split(separator); foreach (char C in myString) { Console.WriteLine("{0}", C); } Console.ReadKey(); } } } The alphabet T and i should be removed ,but when I excuted my codes,It change nothing! Can you tell me why?
-
When I test the String.Trim() function,my resource codes as follows: using System; using System.Collections.Generic; using System.Text; namespace Ch05Ex05 { class Program { static void Main(string[] args) { string myString = " This is a test. "; char[] separator = {' '}; char[] test ={ 'T', 'i' }; string[] myWords; myString = myString.Trim(test); // myWords = myString.Split(separator); foreach (char C in myString) { Console.WriteLine("{0}", C); } Console.ReadKey(); } } } The alphabet T and i should be removed ,but when I excuted my codes,It change nothing! Can you tell me why?
I think you're looking for .Replace. You can replace T with an empty string.
Christian Graus - C++ MVP
-
Trim
removes occurrences only at the begin or at the end of the string (MSDN):String.Trim (Char[])
Removes all occurrences of a set of characters specified in an array from
the beginning and end of this instance.:)
I have got it,Thank you! I'm a new learner on C#.I come from china.Would you mind to make friends with me? I would like that you can help to improve my english and my C#.And if you want to make a journey to china,I can be you guide. MSN:wanlim0817@hotmail.com email:wanlim0817@yahoo.com.cn
-
I think you're looking for .Replace. You can replace T with an empty string.
Christian Graus - C++ MVP
I have got it,Thank you! I'm a new learner on C#.I come from china.Would you mind to make friends with me? I would like that you can help to improve my english and my C#.And if you want to make a journey to china,I can be you guide. MSN:wanlim0817@hotmail.com email:wanlim0817@yahoo.com.cn
-
I have got it,Thank you! I'm a new learner on C#.I come from china.Would you mind to make friends with me? I would like that you can help to improve my english and my C#.And if you want to make a journey to china,I can be you guide. MSN:wanlim0817@hotmail.com email:wanlim0817@yahoo.com.cn
-
When I test the String.Trim() function,my resource codes as follows: using System; using System.Collections.Generic; using System.Text; namespace Ch05Ex05 { class Program { static void Main(string[] args) { string myString = " This is a test. "; char[] separator = {' '}; char[] test ={ 'T', 'i' }; string[] myWords; myString = myString.Trim(test); // myWords = myString.Split(separator); foreach (char C in myString) { Console.WriteLine("{0}", C); } Console.ReadKey(); } } } The alphabet T and i should be removed ,but when I excuted my codes,It change nothing! Can you tell me why?