共用方式為


C# Soup To Nuts: Creating and Manipulating Strings

Today is week 11 of my C# Soup To Nuts webcast series.  I'll be talking about strings today.  Strings can do many wonderful things... mostly, working with text.  We will learn about how to build strings, use them and some of the pitfalls and obstacles we sould avoid when playing around with them.  We will also learn about a cool object called the StringBuilder and see how to use it and why we sould use it.

Join me, the webcast starts at 9am PST right here.

As always, demo code is attached.

Bill

 

Strings.zip

Comments

  • Anonymous
    February 05, 2007
    hi bill, thanks for the presentation. i have a question about the string optimization, there are some cases in the development where we're in the scenario have to replace some characters in a string. e.g : we have defined several special tags that we will replace later in the process the common way is to do a loop to find the tag and replace with the appropriate string, what is the best way to perform this with a minimal resources as we know the string is immutable. thanks in advance

  • Anonymous
    February 12, 2007
    Bembeng, The String.Replace() method should do exactly what you require. Note:  Bill had a problem getting String.Replace() to work in his demo which was not only caused by his previous String.ToUpper() call, but also because the String.Replace() method does not do an "in-place" replacement - it returns the modified string.  So rather than s.Replace(x, y), you must do s = s.Replace(x, y). Tim