Presentation is loading. Please wait.

Presentation is loading. Please wait.

Manipulating Strings String Functions. VB provides a large number of functions that facilitate working with strings. These are found in Microsoft.VisualBasic.Strings.

Similar presentations


Presentation on theme: "Manipulating Strings String Functions. VB provides a large number of functions that facilitate working with strings. These are found in Microsoft.VisualBasic.Strings."— Presentation transcript:

1 Manipulating Strings String Functions

2 VB provides a large number of functions that facilitate working with strings. These are found in Microsoft.VisualBasic.Strings For convenience they can be grouped according to the kind of task they’re designed to carry out.

3 Inspection Functions Inspection functions take a string (or strings) as argument(s) and return information about them in numeric form.

4 Inspection Functions Function NameReturn typeDescription Asc (String1)IntegerReturns an Integer value representing the character code corresponding to a character. Len (String1)IntegerReturns an Integer, the number of characters in String1. InStr ([Start (Integer),] String1, String2) IntegerReturns an Integer specifying the position of the first occurrence of String2 in String1, starting at Start if the argument is specified, otherwise at the beginning of String1. InStrRev (String1, String2, [Start (Integer])) IntegerReturns an Integer specifying the position of the first occurrence of String2 in String1, from the right of String1 (or from Start if the argument is specified. StrComp (String1, String2) IntegerReturns an Integer indicating the comparison of String1 and String2, namely -1, 0 or +1 depending if String1 sorts ahead of, is the same as, or sorts later than String2.

5 Inspection Functions Len(“some text”) InStr(“some text”, “e”) InStr(“some text”, “a”) InStr(5, “some text”, “e”) InStrRev(“some text”, “e”) InStrRev(“some text”, “e”, 5) StrComp(“text”, “test”)

6 Inspection Functions Len(“some text”)9 InStr(“some text”, “e”) InStr(“some text”, “a”) InStr(5, “some text”, “e”) InStrRev(“some text”, “e”) InStrRev(“some text”, “e”, 5) StrComp(“text”, “test”)

7 Inspection Functions Len(“some text”)9 InStr(“some text”, “e”)4 InStr(“some text”, “a”) InStr(5, “some text”, “e”) InStrRev(“some text”, “e”) InStrRev(“some text”, “e”, 5) StrComp(“text”, “test”)

8 Inspection Functions Len(“some text”)9 InStr(“some text”, “e”)4 InStr(“some text”, “a”)0 InStr(5, “some text”, “e”) InStrRev(“some text”, “e”) InStrRev(“some text”, “e”, 5) StrComp(“text”, “test”)

9 Inspection Functions Len(“some text”)9 InStr(“some text”, “e”)4 InStr(“some text”, “a”)0 InStr(5, “some text”, “e”)7 InStrRev(“some text”, “e”) InStrRev(“some text”, “e”, 5) StrComp(“text”, “test”)

10 Inspection Functions Len(“some text”)9 InStr(“some text”, “e”)4 InStr(“some text”, “a”)0 InStr(5, “some text”, “e”)7 InStrRev(“some text”, “e”)7 InStrRev(“some text”, “e”, 5) StrComp(“text”, “test”)

11 Inspection Functions Len(“some text”)9 InStr(“some text”, “e”)4 InStr(“some text”, “a”)0 InStr(5, “some text”, “e”)7 InStrRev(“some text”, “e”)7 InStrRev(“some text”, “e”, 5)4 StrComp(“text”, “test”)

12 Inspection Functions Len(“some text”)9 InStr(“some text”, “e”)4 InStr(“some text”, “a”)0 InStr(5, “some text”, “e”)7 InStrRev(“some text”, “e”)7 InStrRev(“some text”, “e”, 5)4 StrComp(“text”, “test”)1

13 Case Conversion Functions Function NameReturn typeDescription LCase (String1)StringReturns String1 converted to lower case UCase (String1)StringReturns String1 converted to UPPER case These are fairly obvious.

14 SubString Functions There are several functions provided to extract part of string. Function NameReturn typeDescription Left (String1, Length )StringReturns a string containing the specified number of characters from the left of String1. Right (String1, Length )StringReturns a string containing the specified number of characters from the right of String1. Mid (String1, Start, [Length]) StringReturns all (or Length if it is specified) characters from String1 starting at position Start.

15 Formatting Functions Function NameReturn typeDescription LSet (String1, Integer)StringReturns a left-aligned string containing String1 adjusted to the specified length. LTrim (String1)StringReturns a string with blanks removed from the left of String1 RSet (String1, Integer)StringReturns a right-aligned string containing String1 adjusted to the specified length. RTrim (String1)StringReturns a string with blanks removed from the right of String1

16 String Creation Functions Function NameReturn type Description Chr (Integer)CharReturns the character associated with the specified character code. Space (Integer)StringReturns a string composed of blanks, as many as specified by Integer. StrReverse (String1)StringReturns a string composed of the characters from String1 but in reverse order. Join (SourceArray() [,Delimiter]) StringReturns a string created by joining a number of substrings contained in an array. Is a character to be used to separate the strings. Replace (String1, String2, String3, [Start], [Count]) StringReturns a string with String2 replaced by String3, where ever it is found in String1, beginning at position Start, or replaces it Count times from position Start.

17 String Creation Functions Replace (“some people”, “o”, “a”)

18 String Creation Functions Replace (“some people”, “o”, “a”) “same peaple”

19 String Creation Functions Replace (“some people”, “o”, “a”) “same peaple” Replace (“some people”, “o”, “a”,, 1)

20 String Creation Functions Replace (“some people”, “o”, “a”) “same peaple” Replace (“some people”, “o”, “a”,, 1) “same people”

21 String Creation Functions Replace (“some people”, “o”, “a”) “same peaple” Replace (“some people”, “o”, “a”,, 1) “same people” Replace (“some people”, “o”, “a”, 5)

22 String Creation Functions Replace (“some people”, “o”, “a”) “same peaple” Replace (“some people”, “o”, “a”,, 1) “same people” Replace (“some people”, “o”, “a”, 5) “ peaple” Notice that Start indicates the starting character for the Result string.


Download ppt "Manipulating Strings String Functions. VB provides a large number of functions that facilitate working with strings. These are found in Microsoft.VisualBasic.Strings."

Similar presentations


Ads by Google