String Manipulation

1.28 String Manipulation

Asc, AscW Functions

Microsoft.VisualBasic.Strings


Asc(string)
AscW(str)

 

string, str required; String or Char

Any expression that evaluates to a nonempty string

Return Value

An Integer that represents the character code of the first character of the string; the range for the returned value is 0 - 255 on nonDBCS systems, and -32768 to 32767 on DBCS systems

Description

Returns an Integer representing the character code for the first character of the string passed to it. All other characters in the string are ignored.

Chr, ChrW Functions

Microsoft.VisualBasic.Strings


Chr(charcode)
ChrW(charcode)

 

charcode required; Integer

An expression that evaluates to a Unicode character code

Return Value

A Char that contains the character represented by charcode

Description

Returns the character represented by the charcode.

Filter Function

Microsoft.VisualBasic.Strings


Filter(Source, Match[, Include[, Compare]])

 

Source required; String or Object

An array containing values to be filtered.

Match required; String

The substring of characters to find in the elements of the source array.

Include optional; Boolean

A Boolean (True or False) value. If True (the default value), Filter includes all matching values in the returned array; if False, Filter excludes all matching values (or, to put it another way, includes all nonmatching values).

Compare optional; CompareMethod enumeration

A constant whose value can be CompareMethod.Text or CompareMethod.Binary (the default).

Return Value

A 0-based String array of the elements filtered from Source

Description

The Filter function produces an array of matching values from an array of source values that either match or do not match a given filter string. Put another way, individual elements are copied from a source array to a target array if they either match (Include is True) or do not match (Include is False) a filter string.A match occurs for an array element if Match is a substring of the array element.

Format Function

Microsoft.VisualBasic.Strings


Format(expression[, style[, dayofweek[,  weekofyear]]])

 

expression required; String/Numeric

Any valid string or numeric expression

style optional; String

A valid named or user-defined format expression

dayofweek optional; FirstDayOfWeek enumeration

A constant that specifies the first day of the week, as shown in the following table:

Constant

Value

Description

System

0

NLS API setting

Sunday

1

Sunday (default)

Monday

2

Monday

Tuesday

3

Tuesday

Wednesday

4

Wednesday

Thursday

5

Thursday

Friday

6

Friday

Saturday

7

Saturday

weekofyear optional; FirstWeekOfYear enumeration

A constant that specifies the first week of the year, as shown in the following table:

First Week of Year Constants

Constant

Value

Description

UseSystemDayOfWeek

0

Use the NLS API setting

FirstJan1

1

Start with the week in which January 1 occurs (default)

FirstFourDays

2

Start with the first week that has at least four days in the new year

FirstFullWeek

3

Start with first full week of the year

Return Value

A string containing the formatted expression

Description

Allows you to use either predefined or user-defined formats to output string, numeric, and date/time data.

FormatCurrency, FormatNumber,FormatPercent Functions

Microsoft.VisualBasic.Strings


FormatCurrency(expression[,NumDigitsAfterDecimal][, _
  IncludeLeadingDigit[,UseParensForNegativeNumbers[, _
  GroupDigits]]]]) 
FormatNumber(expression[,NumDigitsAfterDecimal][, _
  IncludeLeadingDigit[,UseParensForNegativeNumbers[, _
  GroupDigits]]]]) 
FormatNumber(expression[,NumDigitsAfterDecimal][, _
  IncludeLeadingDigit[,UseParensForNegativeNumbers[, _
  GroupDigits]]]]) 
FormatPercent(expression[,NumDigitsAfterDecimal][, _
  IncludeLeadingDigit[,UseParensForNegativeNumbers[, _
GroupDigits]]]]) 

 

expression required; Object

The number or numeric expression to be formatted.

NumDigitsAfterDecimal optional; Long

The number of digits the formatted string should contain after the decimal point.

IncludeLeadingDigit optional; TriState constant

Indicates whether the formatted string is to have a 0 before floating point numbers between 1 and -1.

UseParensForNegativeNumbers optional; TriState constant

Specifies whether parentheses should be placed around negative numbers.

GroupDigits optional; TriState constant

Determines whether digits in the returned string should be grouped using the delimiter specified in the computer's regional settings. For example, on English language systems, the value 1000000 is returned as 1,000,000 if GroupDigits is True.

Return Value

String

Description

Functions used to format currency, numbers, and percentages. The three functions are almost identical. They all take identical arguments. The only difference is that FormatCurrency returns a formatted number beginning with the currency symbol specified in the computer's regional settings, FormatNumber returns just the formatted number, and FormatPercent returns the formatted number followed by a percentage sign (%).

FormatDateTime Function

Microsoft.VisualBasic.Strings


FormatDateTime(expression[,dateformat])

 

expression required; Date

Date variable or literal date

dateformat optional; DateFormat enum

Defines the format of the date to return

Return Value

String representing the formatted date or time

Description

Formats a date or time expression based on the computer's regional settings.

GetChar Function

Microsoft.VisualBasic.Strings


GetChar(str, index)

 

str required; String

The string from which to extract a character

index required; Integer

Position of character (1-based)

Return Value

A Char containing the character at position index

Description

Returns the character that is at position index within a given string.

InStr Function

Microsoft.VisualBasic.Strings


InStr(start, string1, string2[, compare])  Syntax 1.
InStr(string1, string2[, compare])  Syntax 2.

 

start required in first syntax; Numeric

The starting position for the search

string1 required; String

The string being searched

string2 required; String

The string being sought

compare optional; CompareMethod enumeration

The type of string comparison

Return Value

An Integer indicating the position of the first occurrence of string2 in string1

Description

Finds the starting position of one string within another.

InStrRev Function

Microsoft.VisualBasic.Strings


InstrRev(stringcheck, stringmatch[, start[, compare]])

 

stringcheck required; String

The string to be searched.

stringmatch required; String

The substring to be found within stringcheck.

start optional; Numeric

The starting position of the search. If no value is specified, start defaults to 1.

compare optional; CompareMethod enumeration

A constant indicating how stringcheck and stringmatch should be compared.

Return Value

Long

Description

Determines the starting position of a substring within a string by searching from the end of the string to its beginning.

Join Function

 


 

 

See Join Function entry under Section 1.11.

LCase Function

Microsoft.VisualBasic.Strings


LCase(value)

 

value required; String or Char

A valid string expression or a character

Return Value

String or Char

Description

Converts a string to lowercase.

Left Function

Microsoft.VisualBasic.Strings


Left(str, length)

 

str required; String

The string to be processed

length required; Long

The number of characters to return from the left of the string

Return Value

String

Description

Returns a string containing the leftmost length characters of str.

Len Function

 


 

 

See Len Function entry under Section 1.26.

Like Operator

 


result = string Like pattern

 

string required; String

The string to be tested against pattern

pattern required; String

A series of characters used by the Like operator to determine if string and pattern match

Return Type

Boolean

Description

If string matches pattern, result is True; otherwise, result is False.

LSet Function

Microsoft.VisualBasic.Strings


LSet(Source, Length) 

 

Source required; String

The string to be left aligned

Length required; Integer

The length of the returned string

Return Value

String

Description

Left aligns a string.

LTrim Function

Microsoft.VisualBasic.Strings


LTrim(str)

 

str required; String

A valid string expression

Return Value

String

Description

Removes any leading spaces from str.

Mid Function

Microsoft.VisualBasic.Strings


Mid(str, start[, length])

 

str required; String

The expression from which to return a substring

start required; Long

The starting position of the substring

length optional; Long

The length of the substring

Return Value

String

Description

Returns a substring of a specified length from a given string.

Mid Statement

 


Mid(target, start[, length]) = string

 

target required; String

The name of the string variable to be modified

start required; Long

The position within target at which the replacement commences

length optional; Long

The number of characters in target to replace

string required; String

The string used to replace characters within target

Description

Replaces a section of a string with characters from another string.

Option Compare Statement

 


 
Option Compare {Binary | Text}

 

Description

Used to set the default method for comparing string data. Binary provides for a case sensitive comparison; text provides for a case insensitive comparison in which sort of order is based on the local system's locale settings

Replace Function

Microsoft.VisualBasic.Strings


Replace(expression, find, replace [, start[, _
count[, compare]]])

 

expression required; String

The complete string containing the substring to be replaced

find required; String

The substring to be found by the function

replace required; String

The new substring to replace find in expression

start optional; Long

The character position in expression at which the search for find begins

count optional; Long

The number of instances of find to replace

compare optional; CompareMethod constant

The method used to compare find with expression; its value can be CompareMethod.Binary (for case-sensitive comparison) or CompareMethod.Text (for case-insensitive comparison)

Return Value

The return value from Replace depends on the parameters you specify in the argument list, as the following table shows:

If

Return value

expression = ""

Zero-length string ("")

find = ""

Copy of expression

replace = ""

Copy of expression with all instances of find removed

start > Len(expression)

Zero-length string ("")

count = 0

Copy of expression

Description

Replaces a given number of instances of a specified substring in another string.

Right Function

Microsoft.VisualBasic.Strings


Right(string, length)

 

string required; String

The string to be processed

length required; Integer

The number of characters to return from the right of the string

Return Value

String

Description

Returns a string containing the rightmost length characters of string.

RSet Function

Microsoft.VisualBasic.Strings


RSet(Source, Length)

 

Source required; String

The string to be right aligned

Length required; Integer

The length of the returned string

Return Value

String

Description

Right aligns a string.

RTrim Function

Microsoft.VisualBasic.Strings


RTrim(string)

 

string required; String

A valid string expression

Return Value

String

Description

Removes any trailing spaces from string.

Str Function

 


 

 

See Str Function entry under Section 1.13.

Spc Function

 


 

 

See Spc Function entry under Section 1.21.

Space Function

Microsoft.VisualBasic.Strings


Space(number)

 

number required; Integer

An expression evaluating to the number of spaces required

Return Value

A String containing number spaces

Description

Creates a string containing number spaces.

Split Function

Microsoft.VisualBasic.Strings


Split(expression, [delimiter[, limit[, compare]]])

 

expression required; String

A string to be broken up into multiple strings.

delimiter optional; String

The character used to delimit the substrings in expression.

limit optional; Integer

The maximum number of strings to return.

compare optional; CompareMethod Constant

The method of comparison. Possible values are CompareMethod.Binary (the default) or CompareMethod.Text.

Return Value

A String array containing the substrings of expression delimited by delimiter

Description

Parses a single string containing delimited values into an array.

StrComp Function

Microsoft.VisualBasic.Strings


StrComp(string1, string2[, compare])

 

string1 required; String

Any string expression

string2 required; String

Any string expression

compare optional; CompareMethod constant

Either CompareMethod.Binary or CompareMethod.Text

Return Value

Integer

Description

Determines whether two strings are equal and, if not, which of two strings has the greater value.

StrConv Function

Microsoft.VisualBasic.Strings


StrConv(str, conversion[, localeID])

 

str required; String

The string expression to convert

conversion required; Constant of the VbStrConv enumeration

Constant specifying the type of string conversion.

localeID optional; Integer

The locale identifier to use for the conversion

Return Value

A String converted according to conversion

Description

Performs special conversions on a string.

StrDup Function

Microsoft.VisualBasic.Strings


StrDup(number,character)

 

number required; Integer

The number of times to duplicate the first character in string

character required; String, Char, or Object containing a String or Char

The String or Char whose first character is to be duplicated

Return Value

A String containing the character duplicated the specified number of times

Description

Returns a string that consists of the first character of character duplicated number times.

StrReverse Function

Microsoft.VisualBasic.Strings


StrReverse(expression)

 

expression required; String

The string whose characters are to be reversed

Return Value

String

Description

Returns a string that is the reverse of the string passed to it. For example, if the string and is passed to it as an argument, StrReverse returns the string dna.

Trim Function

Microsoft.VisualBasic.Strings


Trim(str)

 

str required; String

Any string expression

Return Value

String

Description

Removes both leading and trailing spaces from a given string.

UCase Function

Microsoft.VisualBasic.Strings


UCase(value)

 

value required; String

A valid string expression

Return Value

String

Description

Converts a string to uppercase.

Val Function

 


 

 

See Val Function entry under Section 1.13.

VBFixedString Attribute

Microsoft.VisualBasic.VBFixedStringAttribute


 

 

Applies to

Field

Description

Defines a fixed-length string. It is the rough equivalent of the VB 6 declaration:

Dim s As String * length

It can be used to define fixed-length strings within structures, particularly structures that are to be passed to Win32 API functions, as well as to define fixed-length strings to be written to and read from random access files.

Constructor

New(length)

length Integer

The length of the string

Properties

Length Integer

Read-only. The length of the string. Its value is set by the length parameter in the class constructor.

 



VB. NET Language Pocket Reference
VB.NET Language Pocket Reference
ISBN: 0596004281
EAN: 2147483647
Year: 2002
Pages: 31

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net