LabelSelected • Partial Text Selection & More

Blocks and Methods:


Blocks and Methods:

  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.

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

component_method (10)

  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 (11)

  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 (6)

  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 (1)

  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 (8)

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

component_method (9)

  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.

Events:

component_event

  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.

Additional Functions:

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

component_method (3)

  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 (13)

  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 (2)

  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 (12)

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

component_method (4)

  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.).

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 2
LabelSelected.aix (13.5 KB)

Thanks

2 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