From the course: Nail Your C# Interview

Unlock the full course today

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

Access data from strings

Access data from strings - C# Tutorial

From the course: Nail Your C# Interview

Access data from strings

- [Instructor] A common programming task is to search for a piece of data within a string. Depending on the assumptions you make about a string's data you can make an algorithm more or less efficient. If you know nothing about the string you have to check every piece of data within the string in order to find the data you're searching for. If you know the string has its characters in a sorted order then you can optimize the algorithm by starting your search in the front, back, or middle of the string. In all of these cases you'll need to parse the data within the string in order to find the character or substring you're looking for. Let's take a look at how to do that in C#. The least complex, but also least efficient way, to search for a subset of characters within a string is to use the built-in Contains method. We use the Contains method by accessing the string, in this case input, and we say .Contains. We'll see if it…

Contents