String functions

Read(731) Label: string function,

This section introduces string functions used for report making by listing their descriptions, syntax, parameters, return values and options, and giving related examples.

asc()

Description:

Get the Unicode value of a character at the specified position in a string; return ASCII code if the character is recorded in ASCII.

(In general, all the English characters and their extended characters are ASCII characters; Asian language characters, such as Chinese, Japanese and Korean, are recorded in Unicode. ASCII is an 8-bit character set, and Unicode is a 16-bit character set, of which 3 bits are used to indicate the character type).

Related function: char()  Get the corresponding characters according to the given Unicode or ASCII code.

Syntax:

asc( string{, nPos} )

Parameter:

string

A given string

nPos

Integer expression, default is 1

Return value:

Integer type

Example:

Example 1: asc("def")  Return 100  (ASCII)

Example 2: asc("def",2)  Return 101  (ASCII)

Example 3: asc("中国")  Return 20013  (Unicode)

Example 4: asc("中国",2)  Return 22269  (Unicode)

char()

Description:

Get the corresponding characters according to the given Unicode or ASCII code. (In general, all English characters and their extended characters are recorded in ASCII code; Chinese, Japanese, Korean, and other Asian characters are recorded in Unicode characters. ASCII is an 8-bit character set, and Unicode is a 16-bit character set, of which 3 bits are used to indicate the character type).

Related function: asc()  Get the Unicode value of a character at the specified position in a string; return ASCII code if the character is recorded in ASCII.

Syntax:

char( int )

Parameter:

int

Integer expression, Unicode code or ASCII code

Return value:

Character type

Example:

Example 1: char(22269)  Return ''

Example 2: char(101)  Return 'e'

fill()

Description:

Create a new string by concatenating strings together.

Related function: space()  Generate an empty string.

Syntax:

fill(s, n)

Parameter:

s

Source strings for generating a new string

n

Number of source strings that constitute the new string

Return value:

Character type

Example:

Example 1: fill("1 ",10)  Return "1 1 1 1 1 1 1 1 1 1 "

Example 2: fill("a b",10)  Return "a ba ba ba ba ba ba ba ba ba b"

isalpha()

Description:

Judge if a string is composed of letters. If s is an integer, look it up in the ASCII table to see if the corresponding characters are letters.

Syntax:

isalpha(s)

Parameter:

s

A string/ numeric expression

Return value:

Boolean type

Example:

Example 1: isalpha("abc")  Return true

Example 2: isalpha(97)  Return true

Example 3: isalpha("@#$")  Return false

Example 4: isalpha("1@23")  Return false

Example 5: isalpha("a@23")  Return false

isdigit()

Description:

Judge if a string is composed of numbers. If the string is an integer, look it up in the ASCII table to see if the corresponding characters are a number.

Syntax:

isdigit(string)

Parameter:

string

A string/ numeric expression

Return value:

Boolean type

Example:

Example 1: isdigit("123")  Return true

Example 2: isdigit(123)  Return false

Example 3: isdigit("abc")  Return false

Example 4: isdigit("123ss")  Return false

islower()

Description:

Judge if a string is composed of lower-case letters. If the string is an integer, treat it as ASCII code and judge if the corresponding characters are all lower-case letters.

Syntax:

islower(string)

Parameter:

string

A string/ numeric expression

Return value:

Boolean type

Example:

Example 1: islower ("dgfdsgf")  Return true

Example 2: islower (97)  Return true

Example 3: islower ("dsfaAFD")  Return false

Example 4: islower ("97ffdsf")  Return false

isupper()

Description:

Judge if a string is composed of upper-case letters. If the string is an integer, treat it as ASCII code and judge if the corresponding characters are all upper -case letters.

Syntax:

isupper (string)

Parameter:

string

A string/ numeric expression

Return value:

Boolean type

Example:

Example 1: isupper ("ADSFDGKJ")  Return true

Example 2: isupper (85)  Return true

Example 3: isupper ("SDsdsSDAS")  Return false

Example 4: isupper ("8ASDS7")  Return false

left()

Description:

Get a substring of length n starting from the leftmost side of a string. If n<0, the substring’s length is the sum of source string’s length and the value of n.

Related functions:

mid()  Return the substring within a string.

right()  Get a substring of a string ending at the rightmost side.

Syntax:

left(string, n)

Parameter:

string

The source string from which the substring is obtained

n

The length of the substring

Return value:

Character type

Example:

Example 1: left("abcdefg",3)  Return "abc"

Example 2: left("abcdefg",-3)  Return "abcd"

len()

Description:

Compute the length of a string, whose default character set is GB2312. Get length of string’s corresponding Unicode if the character set is not specified.

Syntax:

len(s,cs)

Parameter:

s

A string for which you want to compute the length

cs

A character set; can be omitted

Return value:

An integer

Example:

Example 1: len("adfg")  Return 4

Example 2: len("  abd  ")  Return 7

Example 3: len("报表")  Return 4

Example 4: len("报表","GB2312")  Return 4

Example 5: len("报表","UTF-8")  Return 6

like()

Description:

Judge if a string matches a format string (the asterisk "*" matches 0 or multiple characters; and the question mark "?" matches a single character). An escape character is used to match "*", such as like ("abc*123", "abc\*"), which returns true.

Syntax:

like( stringExp, formatExp)

Parameter:

stringExp

A string expression

formatExp

A format string expression

Return value:

Boolean type

Option:

@c

It makes the matching case-insensitive, while the default is case-sensitive

Example:

Example 1: like( "abc123", "abc*" )  Return true

Example 2: like( "abc123", "abc1?3" )  Return true

Example 3: like( "abc123", "abc*34" )  Return false

Example 4: like( "abc123", "ABC*" )  Return false

Example 5: like("abc*123", "abc\*")  Return true

Example 6: like@c("abc123", "ABC*")  Return true

link()

Description:

Generate a URL.

Syntax:

link(serviceName{,jspArgNames,jspArgValues{,reportArgNames,reportArgValues}}) 

Parameter:

serviceName

Service name

jspArgNames

The array of argument names, which can be empty and where elements must be string type

jspArgValues

The array of argument values, whose length is the same as the number of elements in array jspArgNames

reportArgNames

The array of report argument names, which can be empty and where elements must be string type

reportArgValues

The array of report argument values, whose length is the same as the number of elements in array reportArgNames

Return value:

String type

Example:

Example 1: link("ServiceName",list("jspArg1","jspArg2"), list("value1",2),"count",5)

Return ServiceName?jasArg1=value1&jspArg2=2&params=count=5

lower()

Description:

Convert all characters of a string to lower case.

Related functions:

upper()  Convert all characters in a string to upper case.

wordcap()  Capitalize the first letter of each word in a string.

Syntax:

lower(s)

Parameter:

s

The string you want to convert to lower case

Return value:

Character type

Option:

@q

A quoted string won’t be converted

Example:

Example 1: lower("ABCdef")  Return "abcdef"

Example 2: lower("defABC")  Return "defabc"

Example 3: lower@q("\'AD\'")  Return "'AD'"

mid()

Description:

Get a string’s substring starting from the specified position and of the specified length.

Related functions:

left()  Get a substring starting from the leftmost side of a source string.

right()  Get a substring of a string ending at the rightmost side.

Syntax:

mid(s, start{, end})

Parameter:

s

The source string from which you get the substring

start

The start position of the substring

end

The start position of the substring; by default, the substring’s length will be counted from the start position to the end of the source string

Return value:

String type

Example:

Example 1: mid("abcde",1)  Return abcde

Example 2: mid("abcde",1,2)  Return ab

Example 3: mid("abcde",3)  Return cde

pos()

Description:

Get the position of a substring starting from the specified position in its parent string, and return null if the substring cannot be found.

Syntax:

pos(s1, s2{, begin})

Parameter:

s1

The parent string where you want to search for a substring

s2

Substring of interest

begin

The position from which the search starts; the default start position is1

Option:

@z

Perform the search leftward starting from the position specified by parameter begin, while the search will be done rightward from that position by default

Return value:

Integer type

Example:

Example 1: pos("abcdef","def")  Return 4

Example 2: pos("abcdefdef","def",5)  Return 7

Example 3: pos("abcdef","defa")  Return null

Example 4: pos@z("abcdeffdef ","def",7) Return 4

replace()

Description:

Replace a specified substring of a source string.

Syntax:

replace( src,a,b)

Parameter:

src

Source string

a

A substring of the source string

b

The string with which the specified substring will be replaced

Return value:

A string after the replacement

Option:

@q

A quoted specified string won’t be replaced

Example:

Example 1: replace("abc'abc'def","a","China")  Return "Chinabc'Chinabc'def"

Example 2: replace ("abc'abc'def","a","China")  Return "Chinabc'Chinabc'def"

Example 3: replace@q ("abc'abc'def","a","China")  Return "Chinabc'abc'def"

right()

Description:

Get a substring of length n ending at the rightmost side of a string. If n<0, the substring’s length is the sum of source string’s length and the value of n.

Related functions:

left()  Get a substring starting from the leftmost side of a string.

mid()  Get a substring within a string.

Syntax:

right(s, n)

Parameter:

s

Source string from which you get the substring

n

The length of the target substring

Return value:

String type

Example:

Example 1: right("abced",2)  Return "ed"

Example 2: right("abced",-2)  Return "ced"

rmquote()

Description:

Delete escape characters, and double and single quotation marks in the outermost layer.

Syntax:

rmquote(exp)

Parameter:

exp

An expression

Return value:

String type

Example:

Example 1: rmquote(arg1)  Return s'd'sdwewe; value of variable is "s'd'sd\nwewe"

space()

Description:

Generate an empty string.

Related function: fill()  Create a new string by concatenating strings together.

Syntax:

space(n)

Parameter:

n

Length of the to-be-generated empty string

Return value:

A string generated by concatenating spaces

Example:

Example 1: space(5)  Return "  "

split()

Description:

Split a string into multiple substrings using the delimiter.

Syntax:

split( srcExp,sepExp)

Parameter:

srcExp

A string expression to be split

sepExp

The delimiter expression

Return value:

A list of substrings after the specified string is split

Option:

@q

Parse delimiters within quotation marks and paratheses/brackets; by default, they are not parsed

@a

Retain blank strings on both sides of each substring; by default, remove those blank strings

Example:

Example 1: split("ab;cd;ef;tg;tt",";")

Return array["ab","cd","ef","tg","tt"]

Example 2: split("ab;c'd;e'f;tg;tt",";")

Return array ["ab","c'd;e'f","tg","tt"]  Do not parse delimiters within the quotation marks

Example 3: split("ab;c[d;e]f;tg;tt",";")

Return array ["ab","c[d;e]f","tg","tt"]  Do not parse delimiters within the brackets

Example 4: split@q("ab;c'd;e'f;tg;tt",";")

Return array ["ab","c'd","e'f","tg","tt"]  Parse delimiters within the quotation marks

Example 5: split@q("ab;c[d;e]f;tg;tt",";")

Return array ["ab","c[d","e]f","tg","tt"]  Parse delimiters within the brackets

Example 6: split@a(" ab ,cd,ef,  tg,tt  ",",")

Return array [" ab ","cd","ef","  tg","tt  "]  Retain blank strings on both sides of each substring

trim()

Description:

Remove the blank characters from both ends of a string.

Syntax:

trim(s)

Parameter:

s

Source string from which you want to remove blank characters on both sides

Return value:

String type

Option:

@l

Remove spaces to the left of the string, with the parameter being letter l

@r

Remove spaces to the right of the string; by default, remove spaces on both ends

@a

Remove all extra whitespaces; if there is one or continuous whitespaces within the string, retain only one whitespace; remove the whitespaces between a character and a word, but retain whitespaces within the quotation marks

Example:

Example 1: trim("  abc  ")  Return "abc"

Example 2: trim("  a  bc  ")  Return "a  bc"

Example 3: trim@l(" def abc ")  Return "def abc "

Example 4: trim@r(" abc def ")  Return " abc def"

Example 5: trim@a("a  bc")  Return "a bc"

Example 6: trim@a("a\'  bc\' ")  Return "a'  bc'"

Example 7: trim@a("abc  !")  Return "abc!"

upper()

Description:

Convert all characters in a string to upper case.

Related functions:

lower()  Convert all characters in a string to lower case.

wordcap()  Capitalize the first letter of each word in a string.

Syntax:

upper(s)

Parameter:

s

Source string to be converted to upper case

Return value:

String type

Option:

@q

The quoted strings won’t be converted

Example:

Example 1: upper("ABCdef")  Return "ABCDEF"

Example 2: upper("abcDEF")  Return "ABCDEF"

Example 3: upper@q("\'abCD\'")  Return "'abCD'"

urlencode()

Description:

Encode a URL string.

Syntax:

urlencode(s, cs)

Parameter:

s

A URL string to be encoded

cs

Character set

Return value:

String type

Option:

@r

Decode, which is the inverse operation of urlencode() function

@f

It means that the to-be-encoded string is a complete URL; with this option, the function splits the URL string into different parts and encode each part

Example:

Example 1: urlencode ("哥哥","utf8")  Return "%E5%93%A5%E5%93%A5"

Example 2: urlencode@r("%E5%93%A5%E5%93%A5","utf8")  Return "哥哥"

Example 3: urlencode@f("http://localhost:6868/demo/测试/test.jpg","utf8") 

Return " http://localhost:6868/demo/%E6%B5%8B%E8%AF%95/test.jpg"

wordcap()

Description:

Capitalize the first letter of each word in a string.

Related functions

upper()   Convert all characters in a string to upper case.

lower()  Convert all characters in a string to lower case.

Syntax:

wordcap(s)

Parameter:

s

Source string for which you want to capitalize the first letter of each word

Return value:

String type

Example:

Example 1: wordcap("I love my country")  Return "I Love My Country"

Example 2: wordcap("she is beautiful")  Return "She Is Beautiful"