kony.string Namespace
The kony.string namespace forms the String API and provides the following API elements.
Functions
The kony.string namespace provides the following functions.
This API verifies if any one of the specified set of characters is available in the given string and returns a boolean value.
Syntax
kony.string.containsChars (inputstring, characterArray)
Input Parameters
Parameter | Description |
---|---|
inputstring [String] - Mandatory | Specifies the input string that needs to be verified. |
characterArray [Array] - Mandatory | Specifies the set of characters that need to be searched within the input string. |
Example
In this example, kony.string.containsChars returns true if the input string consists the characters specified in the characterArray. For example, since the input string "abcd|ADV" consists the characters specified in the character array, kony.string.containsChars returns true.
var inputstring = "abdcdADV"; var charsArr = ["|", "-"]; kony.print(kony.string.containsChars(inputstring, charsArr)); // prints false as | and - are NOT contained in the input var inputstring = "abdcd|ADV" kony.print(kony.string.containsChars(inputstring, charsArr)); // prints true as | is contained in the input
Return Values
Return Value | Description |
---|---|
status [Boolean] |
true - if the given input string contains any one of the characters in the specified list. false - if there is an error in the input or if the given input string does not contain any of the specified input characters. |
Exceptions
An error is thrown if input type is invalid or follows an unexpected structure.
102-Invalid input error.
Platform Availability
Available on all platforms.
This API verifies if only (and only) the specified set of characters is available in the given string and returns a boolean value.
Syntax
kony.string.containsOnlyGivenChars (inputstring, characterArray)
Input Parameters
Parameter | Description |
---|---|
inputstring [String] - Mandatory | Specifies the input string that needs to be verified. |
characterArray [Array] - Mandatory | Specifies the set of characters that need to be searched within the input string. |
Example
In this example, kony.string.containsOnlyGivenChars returns true only if the input string consists the characters specified in the characterArray. For example, since the input string "abdcdADV" consists only the characters specified in the character array, kony.string.containsOnlyGivenChars returns true.
//Test case where API returns true var inputStr = "abdcdADV"; var charsArr = ["a", "b", "d", "c", "A", "D", "V"]; var resultantString = kony.string.containsOnlyGivenChars(inputStr,charsArr); frmContainsOnlyGivenChars.containsOnlyGivenCharsLabel.text = resultantString; //Test case where API returns false var inputStr = "abdcdADH"; var charsArr = ["a", "b", "d", "c", "A", "D", "V"]; var resultantString = kony.string.containsOnlyGivenChars(inputStr,charsArr); frmContainsOnlyGivenChars.containsOnlyGivenCharsLabel.text = resultantString;
Return Values
Return value | Description |
---|---|
status [Boolean] |
true - if the given input string contains only the characters in the specified list. false - if there is an error in the input or if the given input string contains any other characters apart from the specified input characters. |
Exceptions
An error is thrown if input type is invalid or follows an unexpected structure.
102-Invalid input error.
Platform Availability
Available on all platforms.
This API verifies that the input string does not contain any of the specified characters and returns a boolean value.
Syntax
kony.string.containsNoGivenChars (inputstring, charsArray)
Input Parameters
Parameter | Description |
---|---|
inputstring [String] - Mandatory | Specifies the input string that needs to be verified. |
charsArray [Array] - Mandatory | Specifies the set of characters that need to be searched within the input string. |
Example
In this example, kony.string.containsNoGivenChars returns true only if the input string does not consist the characters specified in the characterArray. For example, since the input string "abdcdADV" consists none of the characters specified in the character array, kony.string.containsNoGivenChars returns true.
var inputstring = "abdcdADV"; var charsArr = ["|", "-"]; kony.print(kony.string.containsNoGivenChars(inputstring, charsArr)); //prints true as string does not contain the given characters (| and - are NOT contained in the input) var inputstring = "abdcd|ADV"; var charsArr = ["|", "-", "a" ]; kony.print(kony.string.containsNoGivenChars(inputstring, charsArr)); //prints false as string contains the given character "a".
Return Values
Return Value | Description |
---|---|
status [Boolean] |
true - if the given input string contains none of the characters in the specified list. false - if there is an error in the input or if the given input string contains any of the specified input characters. |
Exceptions
An error is thrown if input type is invalid or follows an unexpected structure.
102-Invalid input error.
Platform Availability
Available on all platforms.
This API returns a boolean value indicating if the source string ends with the specified string.
Syntax
kony.string.endsWith(sourcestring, comparestring, ignorecase)
Input Parameters
Parameter | Description |
---|---|
sourcestring [String] - Mandatory | Specifies the source string. |
comparestring [String] - Mandatory | Specifies the string to be compared with the source string. |
ignorecase [Boolean] - Optional | Default value is true, i.e, the comparison is not case sensitive. If you want the comparison to be case sensitive, you must specify the value as false. |
Example
//Returns true since comparison is not case sensitive.The resultant is assigned to a label text. var resultantString = kony.string.endsWith("Kony Solutions", "solutions", true); frmEndsWith.endsWithLabel.text = resultantString;
Return Values
Return Value | Description |
---|---|
boolean |
true - source string ends with compared string. false - source string does not end with compared string. |
Platform Availability
Available on all platforms.
Determines whether two strings contain the same data, ignoring the case of the letters in the String.
Syntax
kony.string.equalsIgnoreCase(string1, string2)
Input Parameters
Parameter | Description |
---|---|
string1 [String] - Mandatory | Specifies the content of the first string. |
string2 [String] - Mandatory | Specifies the content of the second string. |
Example
Perform a kony.string.equalsIgnoreCase on the string "Hello" with another string "HEllo":
var ignorecase = kony.string.equalsIgnoreCase("Hello", "HEllo"); kony.print(ignorecase);
The kony.string.equalsIgnoreCase compares the strings "Hello" and "HEllo" without case sensitivity and returns a Boolean indicating if the strings are a match.
In this example, true is the value returned.
Return Values
Return Value | Description |
---|---|
boolean |
true - both strings contain exactly the same data. false - both strings do not contain exactly the same data |
Platform Availability
Available on all platforms.
This API verifies if the input string contains only ASCII alphabet characters and returns a boolean value.
Syntax
kony.string.isAsciiAlpha (inputstring)
Input Parameters
Parameter | Description |
---|---|
inputstring [String] - Mandatory | Specifies the input string that needs to be verified. |
Example
In this example, the kony.string.isAsciiAlpha API returns true or false based on the input string entered.
var inputstring = "abdcdADV"; kony.print(kony.string.isAsciiAlpha(inputstring)); //prints true var inputstring = "123ab3dcdADV"; kony.print(kony.string.isAsciiAlpha(inputstring)); //prints false
Return Values
Return Value | Description |
---|---|
status [Boolean] |
true - if the input string contains only alphabetic characters. false - if there is an error in the input or the input string contains characters other than alphabet. |
Exceptions
An error is thrown if input type is invalid or follows an unexpected structure.
102-Invalid input error.
Platform Availability
Available on all platforms.
This API verifies if the input string contains only ASCII alphabet characters and numbers, and returns a boolean value.
Syntax
kony.string.isAsciiAlphaNumeric (inputstring)
Input Parameters
Parameter | Description |
---|---|
inputstring [String] - Mandatory | Specifies the input string that needs to be verified. |
Example
In this example, kony.string.isAsciiAlphaNumeric returns true or false based on the input string.
var inputstring = "abdcdADV"; kony.print(kony.string.isAsciiAlphaNumeric(inputstring)); //prints false because the string is not a combination of alphanumeric characters var inputstring = "abcd1234"; kony.print(kony.string.isAsciiAlphaNumeric(inputstring)); //prints true because the string is a combination of alphanumeric characters
Return Values
Return Value | Description |
---|---|
status [Boolean] |
true - if the input string contains only alphanumeric characters. i.e it can contain a string of numbers, characters or a string containing both numbers and characters. false - if there is an error in the input or the input string contains characters other than alphanumeric. |
Exceptions
An error is thrown if input type is invalid or follows an unexpected structure.
102-Invalid input error.
Platform Availability
Available on all platforms.
This API verifies if the input string contains only numeric characters, and returns a boolean value.
Syntax
kony.string.isNumeric (inputstring)
Input Parameters
Parameter | Description |
---|---|
inputstring [String] - Mandatory | Specifies the input string that needs to be verified. |
Example
In this example, kony.string.isNumeric returns true if the input string has only numbers.
kony.print(kony.string.isNumeric("123ab3dcdADV")); // prints false kony.print(kony.string.isNumeric("12344")) ; // prints true
Return Values
Return Value | Description |
---|---|
status [Boolean] |
true - if the input string contains only numeric characters. false - if there is an error in the input or the input string contains characters other than numbers. |
Exceptions
An error is thrown if input type is invalid or follows an unexpected structure.
102-Invalid input error.
Platform Availability
Available on all platforms.
This API verifies if the input string is a valid email address and returns a boolean value.
Syntax
kony.string.isValidEmail (inputstring)
Input Parameters
Parameter | Description |
---|---|
inputstring [String] - Mandatory | Specifies the input string that needs to be verified if it is a valid email address. |
Example
In this example, kony.string.isValidEmail returns true only if the input string comprises a valid email address.
var inputstring = "abcd@"; kony.print(kony.string.IsValidEmail(inputstring)); //prints false as there are no chars after @ var inputstring = "abcd@tccc"; kony.print(kony.string.IsValidEmail(inputstring)); //prints false as the chars after @ does not have . followed by at least 2 chars
Return Values
Return Value | Description |
---|---|
status [Boolean] |
true - if the given input string satisfies the email rules and is a valid email address. false - if there is an error in the input or if the given input string does not satisfy email rules. |
Rules and Restrictions
The API performs the following validations on the input string:
- has at least 6 characters.
- has @.
- has at least 4 characters after @.
- has . (dot) followed by at least 2 characters.
- has at least 1 character before @.
Exceptions
An error is thrown if input type is invalid or follows an unexpected structure.
Platform Availability
Available on all platforms.
This API generates a string which is equivalent to "n copies of the source string concatenated together".
Syntax
kony.string.rep(sourcestring,no)
Input Parameters
Parameter | Description |
---|---|
sourcestring [String] - Mandatory | Specifies the source string. |
no [Number] - Mandatory | Specifies the number of times the source string must be repeated. |
Example
Perform a kony.string.rep operation on the source string "kony":
var resultantString = kony.string.rep("kony",5); frmRep.concatenatedStringLabel.text = resultantString;
The resultant string contains konykonykonykonykony.
Return Values
Return Value | Description |
---|---|
concatenatedstring [String] | A string containing n copies of the source string concatenated together is returned. |
Exceptions
An error is thrown if input type is invalid or does not follow the expected structure.
102-Invalid input error.
Platform Availability
Available on all platforms.
This API reverses the characters in the source string.
Syntax
kony.string.reverse(string)
Input Parameters
Parameter | Description |
---|---|
string [String] - Mandatory | Specifies the source string. |
Example
Perform a reverse operation on the source string "kony":
var resultantString = kony.string.reverse("kony"); frmReverse.reversedStringLabel.text = resultantString;
The resultant string will contain ynok.
Return Values
Return Value | Description |
---|---|
reversedstring [String] | A string containing the characters of the source string in reverse is returned. |
Exceptions
An error is thrown if input type is invalid or does not follow the expected structure.
102-Invalid input error
Platform Availability
Available on all platforms.
This API returns a boolean value indicating if the source string begins with the specified string.
Syntax
kony.string.startsWith(sourcestring, comparestring, ignorecase)
Input Parameters
Parameter | Description |
---|---|
sourcestring [String] - Mandatory | Specifies the source string. |
comparestring [String] - Mandatory | Specifies the string to be compared with the source string. |
ignorecase [Boolean] - Optional | Default value is true. If you do not specify the ignorecase parameter, the comparison of the string will be case insensitive. If you want the comparison to be case sensitive, you must specify the value as false. |
Example
Perform a kony.string.startsWith on the source string "Kony Solutions" for the string "kony" specifying the ignorecase parameter:
var resultantString = kony.string.startsWith("Kony Solutions","kony",true); frmStartsWith.startsWithLabel.text = resultantString;
The kony.string.startsWith compares the source string "Kony Solutions" with the string "kony" without case sensitivity and returns a boolean indicating if the source string begins with the specified string.
In this example, true is the value returned.
Return Values
Return Value | Description |
---|---|
boolean |
true - source string begins with the compared string. false - source string does not begin with the compared string. |
Exceptions
An error is thrown if input type is invalid or does not follow the expected structure.
102-Invalid input error.
Platform Availability
Available on all platforms.
This API removes the leading and ending spaces from the source string.
Syntax
kony.string.trim(string)
Input Parameters
Parameter | Description |
---|---|
string [String] - Mandatory | Specifies the source string. |
Example
Remove the leading and ending spaces in " kony solutions ":
var resultantString = kony.string.trim(" kony solutions "); frmTrim.trimmedStringLabel.text = "\"" + resultantString + "\"";
In this example, kony solutions is the value returned.
Return Values
Return Value | Description |
---|---|
trimmedstring [String] | A string without the leading and ending spaces is returned. |
Exceptions
An error is thrown if input type is invalid or does not follow the expected structure.
102-Invalid input error
Platform Availability
Available on all platforms.