From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Modify string contents

Modify string contents

- [Instructor] Modifying the contents of a string involves using various methods provided by the string class to alter, replace or format strings. We'll look at how to trim a string, change the string case and replace parts of the string. But before we do that, we're saying we're modifying the contents, but remember, strings are immutable. So let's talk about that first. Let's look at line 95. I'm declaring a variable called letters with spaces. Then I'm assigning a string literal, and you can see there are some spaces at the beginning and ending of the string. My goal is to run this trim method, which will remove the spaces at the beginning and end of the string. There's also a trim end, which only removes items from the end of the string, and there's a trim start that only removes items from the start of the string. So what's happening here is it's running this operation and it's assigning the results of that to this variable. Looks like we're modifying it, but what's happening…

Contents