1 / 10

String Manipulation

String Manipulation. Tonga Institute of Higher Education. Introduction. We know how to combine strings together and why this is useful Why is it useful to break strings apart? Extraction of data Example: My birthday is “07-07-1976”. How can we determine the year from this string?

lynne
Download Presentation

String Manipulation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. String Manipulation Tonga Institute of Higher Education

  2. Introduction • We know how to combine strings together and why this is useful • Why is it useful to break strings apart? • Extraction of data • Example: My birthday is “07-07-1976”. How can we determine the year from this string? • How do we break strings apart?

  3. H e l l o 0 2 1 3 4 Index String.SubString Method 1 • Use the SubString method to get a smaller string from a larger string • Example: To get “Sione” from “Sione Tupou” • There are 2 ways to do this • SubString(StartIndex as Integer) • SubString(StartIndex as Integer, Length as Integer) • The index is the location of a letter

  4. H e l l o 0 2 1 3 4 Index String.SubString Method 2 String.SubString(StartIndex as Integer) • The first method has only 1 parameter • It returns everything from that index to the end of the string Prints “Tupou”

  5. H e l l o 0 2 1 3 4 Index String.SubString Method 3 SubString(StartIndex as Integer, Length as Integer) • The second method has only 2 parameter • It returns the letters starting from the first index and continuing for the specified length Prints “Tup”

  6. H e l l o 0 2 1 3 4 Index String.IndexOf Method 1 • Use the indexOf method to get the index number of a letter or string • Example: To find that the index of “e” is 1 • -1 is returned if the string doesn’t exist • There are many different ways to use this method • String.IndexOf(value as Char) • String.IndexOf(value as Char, StartIndex as Integer) • String.IndexOf(value as Char, StartIndex as Integer, Count as Integer) • String.IndexOf(value as String) • String.IndexOf(value as String, StartIndex as Integer) • String.IndexOf(value as String, StartIndex as Integer, Count as Integer) Number of characters to search through Index to begin search from String to Find

  7. H e l l o 0 2 1 3 4 Index String.IndexOf Method 2 • There are many different ways to use this method • String.IndexOf(value as Char) • String.IndexOf(value as Char, StartIndex as Integer) • String.IndexOf(value as Char, StartIndex as Integer, Count as Integer) • String.IndexOf(value as String) • String.IndexOf(value as String, StartIndex as Integer) • String.IndexOf(value as String, StartIndex as Integer, Count as Integer) Returns 1 Find index of string Returns -1 Returns 1

  8. H e l l o 0 2 1 3 4 Index String.IndexOf Method 2 • There are many different ways to use this method • String.IndexOf(value as Char) • String.IndexOf(value as Char, StartIndex as Integer) • String.IndexOf(value as Char, StartIndex as Integer, Count as Integer) • String.IndexOf(value as String) • String.IndexOf(value as String, StartIndex as Integer) • String.IndexOf(value as String, StartIndex as Integer, Count as Integer) Search for “T” from 2 Returns 7 Find index of string Returns 0 Search for “T” from 0 to 5

  9. String.Length Method • To get the number of characters in a string, use the length method Returns 12

  10. More Methods Available • Trim – Removes whitespace before and after string • ToUpper – Changes all characters to upper case • ToLower - Changes all characters to lower case • Check the www.msdn.com or use VS.Net to get a complete list of the methods available

More Related