Label • Select. Copy. Paste. Format. Colors

The Label extension provides functions for selecting text, copying and pasting text, highlighting text, setting text spacing, formatting numbers, sorting text, validating patterns, and handling click events. It also includes a method for changing the color of specific words within text, using a background thread to maintain responsiveness.


Version 1.0

component_method (14)

  1. MakeTextSelectable:
    • Description: This method allows making part of the text in a Label component selectable.
    • Parameters:
      • label: The Label component in which text selection is desired.

component_method (6)

  1. CopyTextToClipboard:
    • Description: This method copies text to the device's clipboard.
    • Parameters:
      • text: The text to be copied to the clipboard.

component_method (17)

  1. SetTextAutoSize:
    • Description: This method sets auto resizing of text to fit in the label component.
    • Parameters:
      • label: The label component for which auto text resizing is desired.
      • enable: A boolean indicating whether to enable (true) or disable (false) auto text resizing.

component_method (18)

  1. SetTextSpacing:
    • Description: This method sets the line and letter spacing of text in the label component.
    • Parameters:
      • label: The label component for which text spacing is desired.
      • lineSpacing: The spacing between lines of text.
      • letterSpacing: The spacing between characters of text.

component_method (13)

  1. HighlightText:
    • Description: This method highlights a specific part of the text in the label component with a given color.
    • Parameters:
      • label: The label component in which text highlighting is desired.
      • startIndex: The start index of the text to be highlighted.
      • endIndex: The end index of the text to be highlighted.
      • color: The color with which to highlight the text.

component_method (7)

  1. CutText:
    • Description: This method cuts the selected text in the label component and copies it to the clipboard.
    • Parameters:
      • label: The label component from which text is to be cut.

component_method (15)

  1. PasteText:
    • Description: This method gets text from the clipboard and returns it as a text string.
    • Parameters: None.

component_method (16)

  1. SearchText:
    • Description: This method searches for specific text within the label component's content and returns the index of the first occurrence.
    • Parameters:
      • label: The label component in which text search is desired.
      • searchText: The text to be searched within the label component.

component_method (12)

  1. GenerateRandomText:
    • Description: Generates random text of the specified length.
    • Parameters:
      • length: The length of the random text to generate.

component_method (9)

  1. ExtractSubstring:
  • Description: Extracts a substring of text from a main string based on the specified start and end indices.
  • Parameters:
    • text: The main string from which to extract the substring.
    • startIndex: The start index of the substring.
    • endIndex: The end index of the substring.

component_method (20)

  1. ValidateText:
  • Description: Validates whether a text string matches a specific pattern using regular expressions.
  • Parameters:
    • text: The text string to be validated.
    • pattern: The regular expression pattern to compare against the text.

component_method (8)

  1. ExtractInformation:
  • Description: Extracts specific information from a text string based on a regular expression pattern and returns a list of matches.
  • Parameters:
    • text: The text string from which to extract information.
    • pattern: The regular expression pattern used to search for information.

component_method (19)

  1. SortText:
  • Description: Sorts a list of text strings in alphabetical order.
  • Parameters:
    • textList: The list of text strings to be sorted.

component_method (11)

  1. FormatNumber:
  • Description: Formats a number into a text string with specific locale and style formatting.
  • Parameters:
    • number: The number to be formatted.
    • locale: The locale setting for number formatting.
    • style: The desired formatting style for the number (e.g., "currency" for currency format, "percent" for percentage format, etc.).

Events:

component_event (4)

  1. AfterTextSelected:
    • Description: This event is triggered after a fragment of text has been selected and copied in the label component.
    • Parameters:
      • selectedText: The selected and copied text.
      • startIndex: The start index of the selected text.
      • endIndex: The end index of the selected text.

Update: Version 1.1

component_method (4)

ChangeWordsColor

  • What it does: Changes the color of specific words within the text of a Label or TextBox.
  • Parameters:
    1. component: The text component (such as a Label or TextBox).
    2. words: List of words to color.
    3. colors: List of colors for the words.

component_method (5)

ClickLabel

  • What it does: Makes a Label clickable like a button.
  • Parameters:
    1. label: The Label to be made clickable.
    2. labelId: Unique identifier of the Label.

component_event (5)

LabelClicked Event

  • What it does: Triggered when a clickable Label is clicked.
  • Parameters:
    1. labelText: Text of the clicked Label.
    2. labelId: Identifier of the clicked Label.

Screenshots Version 1.1

1722761467870

Blocks:



Examples for ValidateText and ExtractInformation functions with regular expression patterns

Examples of ValidateText

Validating an email address

boolean isValidEmail = ValidateText("example@example.com", "^[\\w._%+-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$");
// isValidEmail will be true if the email address is valid.

Validating a phone number (format: (123) 456-7890)

boolean isValidPhone = ValidateText("(123) 456-7890", "^\\(\\d{3}\\) \\d{3}-\\d{4}$");
// isValidPhone will be true if the phone number matches the format.

Validating a URL

boolean isValidURL = ValidateText("https://www.example.com", "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$");
// isValidURL will be true if the URL is valid.

Validating a date in the YYYY-MM-DD format

boolean isValidDate = ValidateText("2023-06-10", "^\\d{4}-\\d{2}-\\d{2}$");
// isValidDate will be true if the date matches the format.

Examples of ExtractInformation

Extracting all email addresses from a text

String text = "Contact us at info@example.com or support@example.org";
YailList emails = ExtractInformation(text, "[\\w._%+-]+@[\\w.-]+\\.[a-zA-Z]{2,6}");
// emails will contain ["info@example.com", "support@example.org"]

Extracting all words starting with an uppercase letter

String text = "The Quick Brown Fox Jumps Over The Lazy Dog";
YailList capitalizedWords = ExtractInformation(text, "\\b[A-Z][a-z]*\\b");
// capitalizedWords will contain ["The", "Quick", "Brown", "Fox", "Jumps", "Over", "The", "Lazy", "Dog"]

Extracting all phone numbers (format: (123) 456-7890) from a text

String text = "Call us at (123) 456-7890 or (987) 654-3210";
YailList phoneNumbers = ExtractInformation(text, "\\(\\d{3}\\) \\d{3}-\\d{4}");
// phoneNumbers will contain ["(123) 456-7890", "(987) 654-3210"]

Extracting all URLs from a text

String text = "Visit https://www.example.com or http://www.test.com for more information";
YailList urls = ExtractInformation(text, "(https?|ftp)://[^\\s/$.?#].[^\\s]*");
// urls will contain ["https://www.example.com", "http://www.test.com"]

Extension: Versión 1.1
JoeDevLabel.aix (18.5 KB)


Thanks.

3 Likes

1 Like

You're right @Anke

I'm changing and adding some functions, I hope some of that can be of help, I didn't find a way to select part of a text and use it in some functions that I need, that's why I decided to make this extension

The idea is if I scan an image, for example a debit card, it gives me all the text that that card has, but I only have to select the number and copy it to the clipboard, I just simplified that function, maybe later I will upload the update.

Updated extension

1 Like

Update: Version 1.1

1 Like