Classic ASP Framework
org.classicasp.primitive.StringEx

The StringEx class is a data type that represents a string of characters. The StringEx class provides methods and properties that let you manipulate core string value types.

To create a StringEx object, you can use the constructor or the global function, or assign a literal value.

Example

	
  Response.Write StringEx("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse enim.").toUpperCase().reverse().strip("[',', '.']").toJSON()
  

Output

"MINE ESSIDNEPSUS TILE GNICSIPIDA RUTETCESNOC TEMA TIS ROLOD MUSPI MEROL"

Summary

Appends the supplied arguments to the end of the String object, converting them to strings if necessary, and returns the resulting string.
Counts the number of occurences of a character in a string.
Returns the character in the position specified by the index parameter.
Returns the numeric ansi character code of the character at the specified index.
Returns a string that only contains specific characters.
Returns a string that has had html content cleaned.
Appends the supplied arguments to the end of the String object, converting them to strings if necessary, and returns the resulting string.
Replaces the values within a string with the values in an array or object.
Replaces the values within a string with the values in an array or object.
Searches the string and returns the position of the first occurrence of vInputValue found at or after startIndex within the calling string.
Determines if the string is alpha.
Determines if the string is alpha numeric.
Determines if the string is lower case.
Determines if the string is upper case.
Searches the string from right to left and returns the index of the last occurrence of vInputValue found before startIndex.
Returns a specified number of characters from the left side of a string.
Returns the length of the string.
Returns an object from a json string.
Returns an object from a url string, parses the following items from url : url, protocol, server, path, port, querystring, and parameters.
Returns an object from a xml string.
Replaces a specified part of a string with another string.
Reverses the characters in the string.
Returns a specified number of characters from the right side of a string.
Determines if a string/array exists in the current string.
Returns a string that includes the startIndex character and all characters up to, but not including, the endIndex character.
Splits a string into an array of substrings by dividing it wherever the specified delimiter parameter occurs using escape character.
Splits a string into an array of substrings by dividing it wherever the specified delimiter parameter occurs.
Returns a string that has had characters stripped from it.
Returns a string that has had html content stripped from it.
Returns a substring consisting of the characters that start at the specified startIndex and with a length specified by len.
Returns a string consisting of the character specified by startIndex and all characters up to endIndex - 1.
Converts unicode characters to ascii characters.
Returns a Bencoded string representation of the object.
Converts a string to an identifier by removing non-alpha-numeric characters, converting to lower-case, and generating an MD5 hash.
Escapes special characters in the unescaped_string, so that it is safe to use in the filesystem, removes ending slash.
Escapes special characters in the unescaped_string, so that it is safe to place it in a query.
Converts text to html and encodes special characters in text to html encoding.
Decodes html encoding in a string.
Encodes special characters in a string to html encoding.
Returns a json encoded string representation of the object.
Returns a copy of this string, with all uppercase characters converted to lowercase.
Returns string padded with characters so that the string's length is at least equal to length .
Returns a string representation of the object.
Returns a copy of this string, with all lowercase characters converted to uppercase.
Decodes special characters in a string to url encoding.
Encodes special characters in a string to url encoding.
Returns an XML encoded string representation of the object.
Removes characters on both sides of a string.
Removes spaces on both the left and the right side of a string.
Removes characters on the right side of a string.
Removes spaces on the left side of a string.
Removes characters on the right side of a string.
Removes spaces on the right side of a string.
Counts the number of words in a string.
Writes a json encoded string representation of the object.
Writes an XML encoded string representation of the object.

add

Public Sub add(ByRef vInputValue)
Appends the supplied arguments to the end of the String object, converting them to strings if necessary, and returns the resulting string.

Returns

N/A

characterCount

Public Function characterCount(ByRef vInputFind)
Counts the number of occurences of a character in a string.

Returns

NumberEx

charAt

Public Function charAt(ByRef lInputIndex)
Returns the character in the position specified by the index parameter.

Returns

StringEx

charCodeAt

Public Function charCodeAt(ByRef lInputIndex)
Returns the numeric ansi character code of the character at the specified index.

Returns

NumberEx

clean

Public Function clean(ByRef vInputFind)
Returns a string that only contains specific characters.

Returns

StringEx

cleanHtml

Public Function cleanHtml()
Returns a string that has had html content cleaned.

Returns

StringEx

concat

Public Function concat(ByRef vInputValue)
Appends the supplied arguments to the end of the String object, converting them to strings if necessary, and returns the resulting string.

Returns

StringEx

format

Public Function format(ByVal vInputValue)
Replaces the values within a string with the values in an array or object.

Returns

StringEx

Example 1

		
	  Response.Write StringEx("The number is {0}").format(ArrayEx("1000")).toJSON()
	  

Example 1 Output

"The number is 1000"

Example 2

		
	  Response.Write StringEx("The name is {name} and the color is {color}").format(ObjectEx("{'name':'My Object', 'color':'red'}")).toJSON()
	  

Example 2 Output

"The name is My Object and the color is red"

formatEx

Public Function formatEx(
ByVal vInputValue,
ByRef vInputName)
Replaces the values within a string with the values in an array or object.

Returns

StringEx

Example 1

		
	  Response.Write StringEx("The number is {example_0}").formatEx(ArrayEx("1000"), "example_").toJSON()
	  

Example 1 Output

"The number is 1000"

Example 2

		
	  Response.Write StringEx("The name is {example_name} and the color is {example_color}").formatEx(ObjectEx("{'name':'My Object', 'color':'red'}"), "example_").toJSON()
	  

Example 2 Output

"The name is My Object and the color is red"

indexOf

Public Function indexOf(
ByRef vInputValue,
ByRef lInputIndex)
Searches the string and returns the position of the first occurrence of vInputValue found at or after startIndex within the calling string.

Returns

NumberEx

isAlpha

Public Function isAlpha()
Determines if the string is alpha.

Returns

BooleanEx

isAlphaNumeric

Public Function isAlphaNumeric()
Determines if the string is alpha numeric.

Returns

BooleanEx

isLowerCase

Public Function isLowerCase()
Determines if the string is lower case.

Returns

BooleanEx

isUpperCase

Public Function isUpperCase()
Determines if the string is upper case.

Returns

BooleanEx

lastIndexOf

Public Function lastIndexOf(
ByRef vInputValue,
ByRef lInputIndex)
Searches the string from right to left and returns the index of the last occurrence of vInputValue found before startIndex.

Returns

NumberEx

leftEx

Public Function leftEx(ByRef lInputLength)
Returns a specified number of characters from the left side of a string.

Returns

StringEx

length

Public Function length()
Returns the length of the string.

Returns

NumberEx

parseJSON

Public Function parseJSON()
Returns an object from a json string.

Returns

Variant

parseURL

Public Function parseURL()
Returns an object from a url string, parses the following items from url : url, protocol, server, path, port, querystring, and parameters.

Returns

ObjectEx

parseXML

Public Function parseXML()
Returns an object from a xml string.

Returns

Variant

replaceEx

Public Function replaceEx(
ByRef vInputPattern,
ByRef vInputReplacement)
Replaces a specified part of a string with another string.

Returns

StringEx

reverse

Public Function reverse()
Reverses the characters in the string.

Returns

StringEx

rightEx

Public Function rightEx(ByRef lInputLength)
Returns a specified number of characters from the right side of a string.

Returns

StringEx

search

Public Function search(
ByRef vInputFind,
ByRef bInputExactMatch)
Determines if a string/array exists in the current string.

Returns

BooleanEx

slice

Public Function slice(
ByRef lInputIndexStart,
ByRef lInputIndexEnd)
Returns a string that includes the startIndex character and all characters up to, but not including, the endIndex character.

Returns

StringEx

splitEscapeEx

Function splitEscapeEx(
ByVal oInputDelimiter,
ByVal oInputEscape)
Splits a string into an array of substrings by dividing it wherever the specified delimiter parameter occurs using escape character.

Returns

ArrayEx

splitEx

Public Function splitEx(ByRef vInputPattern)
Splits a string into an array of substrings by dividing it wherever the specified delimiter parameter occurs.

Returns

ArrayEx

strip

Public Function strip(ByRef vInputFind)
Returns a string that has had characters stripped from it.

Returns

StringEx

stripHtml

Public Function stripHtml()
Returns a string that has had html content stripped from it.

Returns

StringEx

substr

Public Function substr(
ByRef lInputIndexStart,
ByRef lInputLength)
Returns a substring consisting of the characters that start at the specified startIndex and with a length specified by len.

Returns

StringEx

substring

Public Function substring(
ByRef lInputIndexStart,
ByRef lInputIndexEnd)
Returns a string consisting of the character specified by startIndex and all characters up to endIndex - 1. If endIndex is not specified, String.length is used. If the value of startIndex equals the value of endIndex, the method returns an empty string. If the value of startIndex is greater than the value of endIndex, the parameters are automatically swapped before the function executes.

Returns

StringEx

toAscii

Public Function toAscii()
Converts unicode characters to ascii characters.

Returns

StringEx

toBencode

Public Function toBencode()
Returns a Bencoded string representation of the object.

Returns

String

Example

		
	  Response.Write StringEx("test").toBencode()
	  

Output

4:test

toEID

Public Function toEID()
Converts a string to an identifier by removing non-alpha-numeric characters, converting to lower-case, and generating an MD5 hash.

Returns

StringEx

toEscapePath

Public Function toEscapePath()
Escapes special characters in the unescaped_string, so that it is safe to use in the filesystem, removes ending slash.

Returns

StringEx

toEscapeSql

Public Function toEscapeSql()
Escapes special characters in the unescaped_string, so that it is safe to place it in a query.

Returns

StringEx

toHtml

Public Function toHtml()
Converts text to html and encodes special characters in text to html encoding.

Returns

StringEx

toHtmlDecode

Public Function toHtmlDecode()
Decodes html encoding in a string.

Returns

StringEx

toHtmlEncode

Public Function toHtmlEncode()
Encodes special characters in a string to html encoding.

Returns

StringEx

toJSON

Public Function toJSON()
Returns a json encoded string representation of the object.

Returns

String

Example

		
	  Response.Write StringEx("test").toJSON()
	  

Output

"test"

toLowerCase

Public Function toLowerCase()
Returns a copy of this string, with all uppercase characters converted to lowercase.

Returns

StringEx

toPaddedString

Public Function toPaddedString(
ByRef sInputCharacter,
ByRef lInputLength)
Returns string padded with characters so that the string's length is at least equal to length.

Returns

StringEx

toString

Public Function toString()
Returns a string representation of the object.

Returns

StringEx

toUpperCase

Public Function toUpperCase()
Returns a copy of this string, with all lowercase characters converted to uppercase.

Returns

StringEx

toUrlDecode

Public Function toUrlDecode()
Decodes special characters in a string to url encoding.

Returns

StringEx

toUrlEncode

Public Function toUrlEncode()
Encodes special characters in a string to url encoding.

Returns

StringEx

toXML

Public Function toXML()
Returns an XML encoded string representation of the object.

Returns

String

Example

		
	  Response.Write StringEx("test").toXML()
	  

Output

<data type="String">test</data>

trimCharEx

Public Function trimCharEx(ByRef vInputValue)
Removes characters on both sides of a string.

Returns

StringEx

trimEx

Public Function trimEx()
Removes spaces on both the left and the right side of a string.

Returns

StringEx

trimLeftCharEx

Public Function trimLeftCharEx(ByRef vInputValue)
Removes characters on the right side of a string.

Returns

StringEx

trimLeftEx

Public Function trimLeftEx()
Removes spaces on the left side of a string.

Returns

StringEx

trimRightCharEx

Public Function trimRightCharEx(ByRef vInputValue)
Removes characters on the right side of a string.

Returns

StringEx

trimRightEx

Public Function trimRightEx()
Removes spaces on the right side of a string.

Returns

StringEx

wordCount

Public Function wordCount(ByRef vInputFind)
Counts the number of words in a string.

Returns

NumberEx

writeJSON

Public Sub writeJSON()
Writes a json encoded string representation of the object.

Returns

N/A

Example

		
	  Call StringEx("test").writeJSON()
	  

Output

"test"

writeXML

Public Sub writeXML()
Writes an XML encoded string representation of the object.

Returns

N/A

Example

		
	  Call StringEx("test").writeXML()
	  

Output

<data type="String">test</data>

'***ClassicASP.org
'Copyright 2010 ClassicASP.org

'This file is part of ClassicASP Framework.

'ClassicASP-Framework is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, version 3 of the License.

'ClassicASP-Framework is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with ClassicASP-Framework. If not, see .

'For additional information please visit .