File size

File size

File size

File size

File size

24.1 MB

Since often times in our applications we'll want to work with string data, this lesson will approach a number of different string manipulations, whether changing the manner in which it is displayed to the end user through String.Format() and the formatting syntax like {0:C} or through using escape sequences to include characters otherwise reserved by C# for other purposes. We'll look at built-in String methods to manipulate the content inside of a literal string, and will look at the StringBuilder class for concatenating many strings together in a memory and resource friendly manner.

@Arwen: Thanks for the heads up ... I'll make sure the good folks at Channel9 see this issue. Thanks again!

@Naqi Agha: Object Oriented Programming (beyond the absolute basics) was NOT covered in this Channel9 Fundamentals series. I do talk about classes, properties, methods, and inheritance in this series, but I don't really address the OOP thought process here. Sorry, it just wasn't in the scope of what the Channel9 team was looking for.

I love your style and I can easily follow you. These videos are excellent especially for a beginner like me in C#. Can you kindly direct me to a lesson which will teach me how to read html tables from a webpage and then use these numbers in further calculations. Does a string become a number?

@thens: Probably so ... Intellisense should guide you (even if it didn't show up in the video I created ... ??)

@Jose Roberto: Unfortunately that's not something I can fix ... you will need to get Microsoft's attention by clicking the Feedback link in the Footer of this site so they can repair the links. Thanks for the heads up.

@jake123: Thanks for the kind words ... I don't have a free lesson on scraping a website, but I know there are a bunch of articles out there on the web that describe the technique. It definitely can be done. Search for terms like "web page scraping C#" or the like. Best wishes!

@Krati: Bummer ... I hate when that happens. Try searching in your favorite search engine for the keywords ... I'm sure they just moved it somewhere new.

re: Spaces in between words ... there are probably several ways to accomplish this. I'm not in a code editor, but you would do something like this (syntax might be off a bit):

var myNewString = myOldString.Replace(" ", " ");

Note ... I would send in the "bad" string (with two spaces between double-quotes) as the first parameter, and the "good"string (with one space between double-quotes).

If you need to be more selective, you might need to turn the entire string into a char array and loop through every character in the string looking for a sequence that fits the criteria you need. That would allow for a pretty advanced case, but would be code intensive. Hope that helps!

I am a beginner and find your videos extremely informative and helpful.I have a doubt regarding the way while loop functions, how is the while function able to move onto the next line in the txt file with out us telling it to. I mean in the for loop we have to increment the value everytime the loop finishes and so it moves on to the next.

@BobTaborFan: String are immutable objects. That means every time you do something to it, like string foo = foo + "bar"; you actually create a new string rather than altering the original! This can become costly and actually become a performance hit. StringBuilder is a class that prevents that scenario from happening.

Error 1 'System.Text.StringBuilder' does not contain a definition for 'Substring' and no extension method 'Substring' accepting a first argument of type 'System.Text.StringBuilder' could be found (are you missing a using directive or an assembly reference?) c:\users\edarl_000\documents\visual studio 2012\Projects\ConsoleApplication5\ConsoleApplication5\Program.cs 32 40 ConsoleApplication5

@Erik: depends on what types of additional formatting you want to do. StringBuilder does have a .ToString(int startIndex, int length) property which is basically substring. Remember to do some stuff certain ways, you need to craft it back into something that is useable or build the tools to do what you want.

@lasseran: I did a quick test here and what I saw was the default console font lacks the Euro symbol. If I did a breakpoint and looked at the output from within VS, it did have the 123.45 €

You can flip your console's default font if you want or change your Console.WriteLine to Debug.Writeline where it outputs to the output window from with-in Visual Studio and you'll get the proper symbol too.

Hi..Bob ..thank u very much for video ..i have been listening your video since last month which really helped me to learn c#program..again thanks for giving us this kind of service..But after a month i realized that it would be more effective if we will have some homework or exercise at the end of the video....dont mind Bob its my just personal request and kind of suggestion as well ..by the way i m not trying to smart anyway ...if u have something for exercise plz plz it will be appreciated ..thank u Bob..u have really wonderful teaching style:):)

Remove this comment

Remove this thread

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums, or
Contact Us and let us know.