German version   Deutsche Version


Download

Usage

Reference

Properties

Methods

Events

Example

Tools


Version History

Version Modification
1.0 (2024-06-15) Initial version
1.1 (2025-04-20) getASCIICode, getASCIIChar added.
1.2 (2025-09-02) ReplaceFirst..., ReplaceLast..., IndexOf..., LastIndexOf..., isEmailOf..., isInetAddressOf..., isInet6AddressOf..., isInetAddressOf... added.

Download

The ZIP archive UrsAI2StringUtils for downloading. The archive contains the source code and the compiled binary and a sample project to upload to the App Inventor.

Usage

This extension offers a number of auxiliary functions for editing texts. These are taken from the Apache String Utils (source code on GitHub).

Many functions exist in two or three variants:

 

Reference

Properties

Text
Defines the text to be edited or retrieves it.
Version
Returns the version of this extension.
VersionSDK ()
Returns running Android SDK version.

Methods

Abbreviate (Marker, MaxWidth)
Get an abbreviation of the set text using a given replacement marker. This will turn "Now is the time for all good men." into "Now is the time for..." if "..." was defined as the replacement marker. The set text will not be changed.
AbbreviateOf (Text, Marker, MaxWidth)
Abbreviates a text using a given replacement marker. This will turn "Now is the time for all good men." into "Now is the time for..." if "..." was defined as the replacement marker.
AbbreviateThis (Marker, MaxWidth)
Abbreviates the set text using a given replacement marker. This will turn "Now is the time for all good men." into "Now is the time for..." if "..." was defined as the replacement marker.
Center (Size, PadChar)
Gets the set text centered in a larger text of size Size. The set text will not be changed.
CenterOf (Text, Size, PadChar)
Centers a text in a larger text of size Size.
CenterThis (Size, PadChar)
Centers the set text in a larger text of size Size.
CharAt (Index)
Gets the character at position Index (1 based) of the set text. Returns "" if Index > length of the set text.
CharAtOf (Text, Index)
Gets the character at position Index (1 based) of a text. Returns "" if Index > length of the text.
EndsWith (Suffix, IgnoreCase)
Checks if the set text ends with a specified suffix (optionally case insensitive).
EndsWithOf (Text, Suffix, IgnoreCase)
Checks if a text ends with a specified suffix (optionally case insensitive).
getASCIIChar (Code)
Returns the ASCII character associated with the value of Code (65 → 'A'). Code must have a value between 0..127. If the value is outside this range, an empty string ("") is returned.
getASCIICode (Source)
Returns the ASCII code of the first character of Source. This character must have a code in the value range 0..127, i.e. it must not be a language-specific character such as German umlauts ÄÖÜäüöß. If the ASCII code cannot be determined, -1 is returned.
IsDigit (CharAt)
Returns true if the character at position CharAt (1 based) of the set text is a digit (see Character.isDigit). Returns false if CharAt > length of the set text.
IsDigitOf (Text, CharAt)
Returns true if the character at position CharAt (1 based) of Text is a digit (see Character.isDigit). Returns false if CharAt > length of the Text.
isEmailOf (Text)
Checks if the given text is an valid email address. Uses Apache Common Validators.
isEmailOfThis (Text)
Checks if the set text is an valid email address. Uses Apache Common Validators.
IsEmpty (CharAt)
Checks if the set text is empty ("").
IsEmptyOf (Text, CharAt)
Checks if Text is empty ("").
isInet4AddressOf (Text)
Checks if the given text is an valid IPv4 address.
isInet4AddressOfThis (Text)
Checks if the set text is an valid IPv4 address.
isInet6AddressOf (Text)
Checks if the given text is an valid IPv6 address.
isInet6AddressOfThis (Text)
Checks if the set text is an valid IPv6 address.
isInetAddressOf (Text)
Checks if the given text is an valid IPv4 or IPv6 address.
isInetAddressOfThis (Text)
Checks if the set text is an valid IPv4 or IPv6 address.
IsLetter (CharAt)
Returns true if the character at position CharAt (1 based) of the set text is a letter (see Character.isLetter). Returns false if CharAt > length of the set text.
IsLetterOf (Text, CharAt)
Returns true if the character at position CharAt (1 based) of Text is a letter (see Character.isLetter). Returns false if CharAt > length of Text.
IsLetterOrDigit (CharAt)
Returns true if the character at position CharAt (1 based) of the set text is a letter or a digit (see Character.isLetter, Character.isDigit). Returns false if CharAt > length of the set text.
IsLetterOrDigitOf (Text, CharAt)
Returns true if the character at position CharAt (1 based) of Text is a letter or a digit (see Character.isLetter, Character.isDigit). Returns false if CharAt > length of Text.
IndexOf (Text, Segment)
Returns the index within the given text of the first occurrence of the specified substring. The index is 1-based. 0 is returned if Segment is not contained in the specified text.
IndexOfThis(Segment)
Returns the index within the set text of the first occurrence of the specified substring. The index is 1-based. 0 is returned if Segment is not contained in the set text.
IsWhiteSpace (CharAt)
Returns true if the character at position CharAt (1 based) of the set text is whitespace (see Character.isWhiteSpace). Returns false if CharAt > length of the set text.
IsWhiteSpaceOf (Text, CharAt)
Returns true if the character at position CharAt (1 based) of Text is a whitespace (see Character.isWhiteSpace). Returns false if CharAt > length of Text.
LastIndexOf (Text, Segment)
Returns the index within the given text of the last occurrence of the specified substring. The index is 1-based. 0 is returned if Segment is not contained in the specified text.
LastIndexOfThis (Segment)
Returns the index within the set text of the last occurrence of the specified substring. The index is 1-based. 0 is returned if Segment is not contained in the set text.
Left (Count)
Gets the leftmost Count characters of the set text.
LeftOf (Text, Count)
Gets the leftmost Count characters of Text.
LeftThis (Count)
Sets the stored text to the leftmost Count characters of the set text.
LeftPad (Size, PadChar)
Gets the set text left padded with the specified character. Size is the final size of the text. The set text will not be changed.
LeftPadOf (Text, Size, PadChar)
Left pad a text with a specified character. Size is the final size of the text.
LeftPadThis (Size, PadChar)
Left pad the set text with a specified character. Size is the final size of the text.
LevenshteinDistance (Left, Right)
Find the Levenshtein distance between two Strings. A higher score indicates a greater distance.
Mid (Start, Count)
Gets Count characters from the middle of the set text.
MidOf (Text, Start, Count)
Gets Count characters from the middle of Text.
MidThis (Start, Count)
Sets the stored text to Count characters from the middle of the set text.
RemoveFirstChar ()
Gets the set text without the first character. The set text will not be changed.
RemoveFirstCharOf (Text)
Removes the first character from Text.
RemoveFirstCharOfThis ()
Removes the first character from the set text.
RemoveLastChar ()
Gets the set text without the last character. The set text will not be changed.
RemoveLastCharOf (Text)
Removes the last character from Text.
RemoveLastCharOfThis ()
Removes the last character from the set text.
Repeat (Text, Count)
Repeat Text Count times to form a new text.
ReplaceFirst (Segment, Replacement)
Gets the set text with first occurrence of Segment replaced by Replacement. The set text will not be changed.
ReplaceFirstOf (Text, Segment, Replacement)
Replaces the first substring of Text that matches the given Segment with the given Replacement.
ReplaceFirstOfThis (Segment, Replacement)
Replaces the first substring of the set text that matches the given Segment with the given Replacement.
ReplaceLast (Segment, Replacement)
Gets the set text with last occurrence of Segment replaced by Replacement. The set text will not be changed.
ReplaceLastOf (Text, Segment, Replacement)
Replaces the last substring of Text that matches the given Segment with the given Replacement.
ReplaceLastOfThis (Segment, Replacement)
Replaces the last substring of the set text that matches the given Segment with the given Replacement.
Gets the rightmost Count characters of the set text.
RightOf (Text, Count)
Gets the rightmost Count characters of Text.
RightThis (Count)
Sets the stored text to the rightmost Count characters of the set text.
RightPad (Size, PadChar)
Gets the set text right padded with the specified character. Size is the final size of the text. The set text will not be changed.
RightPadOf (Text, Size, PadChar)
Fills Text on the right with the specified character. Size is the final size of the text.
RightPadThis (Size, PadChar)
Fills the stored text on the right with the specified character. Size is the final size of the text.
StartsWith (Prefix, IgnoreCase)
Checks if the set text starts with the specified Prefix (optionally case insensitive).
StartsWithOf (Text, Prefix, IgnoreCase)
Checks if Text starts with the specified Prefix (optionally case insensitive).
SwapCase ()
Gets a case swapped version of the set text changing upper and title case to lower case, and lower case to upper case.
SwapCaseOf (Text)
Swaps the case of Text changing upper case to lower case, and lower case to upper case.
SwapCaseThis ()
Swaps the case of the set text changing upper and title case to lower case, and lower case to upper case.

Events

None

Example

The example applies many of the defined functions to an entered text:

Beispiele zu den String Utilities

 

Tools

For developing own extensions I gathered some tips: AI2 FAQ: Develop Extensions.