String Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > String commands > !STR.- String Command >

String Operations

STR. - String - Command

Previous Top Next


MiniRobotLanguage (MRL)

 

STR. Command

String commands

 

 

Intention

 

These commands have been improved a lot and contain nearly everything you can find with most popular BASIC Languages also.

And more.

 

The new String Commands include especially LEFT$. MID$, RIGHT$, several Types of INSTR, working with Delimited Strings and also special Commands for use with A.I. Commands.

The Command "STR.Del Prefix" is specially designed to remove a possible "Prefix" like "Certainly you can ...:" like it is used from ChatGPT often.

Also there are "Grab-Commands" which will take several delimited Strings out of a Source String. And much more ...

Unlike the commands below, These new commands are not optimized for binary data, as the commands below, because they need to do a full variable resolution.

Exploring the New STR Commands: A Comprehensive Guide

In this section, we'll delve into the intricacies of our newly introduced STR commands to help you understand their functionalities and use-cases more clearly.

The STR.CONTAINS and STR.CONTAINS Commands

The STR.CONTAINS commands are designed to check if a given string (or set of strings) is present within a larger string. For instance, if you have three strings—String1, String2, and String3—and you wish to verify if any of these strings appear in a larger text, you can employ these commands.

STR.CI-CONTAINS: This is the case-insensitive version of the STR.CONTAINS command. It disregards the case of the characters in the strings being searched for.

STR.NORMAL-CONTAINS: Unlike STR.CI-CONTAINS, this version is case-sensitive, meaning it will only find matches that have the exact same case as the search strings.

Introducing the STR.CLIP Command Group

The STR.CLIP command group consists of three distinct commands:

STR.CLIP-LEFT: This command removes characters from the left side of a string.

STR.CLIP-RIGHT: This command eliminates characters from the right side of a string.

STR.CLIP-MIDDLE: This command is designed to remove characters from the middle of a string.

The STR.COUNT and STR.COUNT-ANY Commands

These commands are used to count the occurrences of a substring within a larger string. The key difference between the two lies in how they count:

STR.COUNT: This command counts the entire substring as a single entity. All characters in the substring must match for it to be counted.

STR.COUNT-ANY: Unlike STR.COUNT, this command counts each character in the substring individually. It operates on the basis of individual characters, counting each occurrence of any of the specified characters within the main string.

 

Exploring Additional STR Commands: An In-Depth Look

In this section, we'll continue to explore more specialized STR commands that offer unique functionalities tailored for specific use-cases.

The STR.DELETE-PREFIX Command

The STR.DELETE-PREFIX command is engineered to remove unwanted prefixes from a string, making it particularly useful when working with outputs from AI systems like ChatGPT. For instance, you might receive a response like "Certainly, you can do this and this and this: The actual answer." The command will strip away the prefix, leaving you with just the essential information, "The actual answer."

The STR.EXTRACT and STR.EXTRACT-ANY Commands

These commands are designed to work with delimited strings. They allow you to extract specific portions of a string based on a delimiter.

STR.EXTRACT: This command extracts a segment of a string based on a specified delimiter. For example, if you have a string "apple,banana,pear," and your delimiter is a comma, STR.EXTRACT could retrieve "apple" or "banana" depending on your specified parameters.

STR.EXTRACT-ANY: Similar to STR.EXTRACT, this command also works with delimited strings but offers more flexibility by allowing you to specify multiple delimiters.

The STR.FIND-BEST-MATCH Command

This command is particularly useful for implementing voice-activated menus or commands. It's designed to find the closest match to a given word within a predefined list. For example, if you're using the Smart Package Robot for dictation, this command can enhance its functionality by allowing you to create a voice-activated menu.

When you input a word, STR.FIND-BEST-MATCH scans through a list of menu options and identifies the closest match using an intelligent algorithm. It then returns the index of the matched menu option, allowing you to easily determine the user's selection even if the voice input wasn't perfectly clear.

 

In-Depth Exploration of Advanced STR Commands for Nested and Delimited Strings

In this section, we'll delve into a set of specialized STR commands designed to handle nested structures and delimited strings. These commands offer precise control over string manipulation, making it easier to work with complex data formats like XML or sentences with quotations.

The STR.GET-NESTED Command

The STR.GET-NESTED command is tailored for handling nested structures, such as XML or JSON. It allows you to extract specific portions of a string based on nesting levels. For example, if you have an XML structure with multiple nested tags, you can use STR.GET-NESTED to retrieve all elements from a specified nesting level and below.

The STR.GRAB-BETWEEN Command

While similar to STR.GET-NESTED, the STR.GRAB-BETWEEN command has a more focused scope. It extracts only the content at a specific nesting level, ignoring all higher and lower levels. This makes it ideal for isolating specific elements within a nested structure.

The STR.GRAB-QUOTED Command

This command is designed to extract quoted segments from a string, such as sentences or phrases enclosed in quotation marks. By specifying an index, you can retrieve the first, second, third, or any other quoted segment within the string. This is particularly useful for parsing dialogue or extracting specific quotes from a larger text.

The STR.GRAB-SINGLE and STR.GRAB-DELIMITED Commands

Both of these commands are geared towards working with delimited strings, but they offer different levels of flexibility:

STR.GRAB-SINGLE: This command allows you to extract a segment from a string based on a multi-character delimiter. Unlike other commands, STR.GRAB-SINGLE supports delimiters of any length, offering greater flexibility in parsing complex strings.

STR.GRAB-DELIMITED: This command is similar to STR.GRAB-SINGLE but is restricted to single-character delimiters. It's optimized for speed and is ideal for simpler delimited strings.

 

 

Comprehensive Guide to New In-String and Mid-String Commands

In this section, we'll explore the latest additions to our suite of in-string and mid-string commands, designed to offer you unparalleled control and flexibility in string manipulation. These commands come with multiple variations to cater to different use-cases, making them highly versatile tools in your programming arsenal.

Enhanced STR.INSTRING Commands

We've expanded the capabilities of the STR.IN-STRING command to include several new variations:

Case-Insensitive STR.I-INSTR: This version allows you to search for a substring within a main string without regard to case sensitivity.

Position-Specific STR.XINSTR and "STR.XNINSTR": This variant lets you specify a starting position for the search, providing more targeted results.

Case-Sensitive STR.INSTR: This is the standard version that performs a case-sensitive search within the main string.

These three new types of STR.INSTRING commands offer greater flexibility and precision in your string search operations.

Advanced STR.MID-STRING Commands

The STR.MID-STRING command is a staple in BASIC languages, and we've taken it a step further by offering two distinct functionalities:

Function Form of STR.MID-STRING: This is the query-based version that allows you to extract a specific substring from a main string. For example, you can retrieve the next seven characters starting from the fifth character.

Statement Form of STR.MID-STRING: This version allows you to modify a specific range within the main string. For instance, you can change characters from the fifth to the seventh position.

For both the function and statement forms, we offer two options:

Standard STR.MID-STRING: Here, you specify the starting point and the number of characters you want to extract or modify.

Extended STR.MID-STRING-TO: This version allows you to specify both the starting and ending positions, offering even more control over the substring you wish to manipulate.

 

 

Introducing Advanced String Manipulation Commands: Shrink, Split, Wrap, and Unwrap

In this section, we'll delve into some of the newest commands designed to give you even more control over string manipulation. These commands are particularly useful for standardizing delimiters, splitting strings, and managing brackets. Let's take a closer look at each of these powerful features.

STR.SHRINK: Standardize Delimiters

The STR.SHRINK command is designed to standardize the number of delimiters in a delimited string. For instance, if you have a sentence and you want to ensure that there is only a single space between each word, STR.SHRINK is the tool for the job. It removes extra spaces or other delimiters, leaving you with a neatly formatted string.

STR.SPLITSTRING: Efficient String Splitting

The STR.SPLITSTRING command allows you to instantly divide a delimited string into two separate parts, each stored in its own variable. This is particularly useful when you need to quickly dissect a string for further processing.

STR.WRAP and STR.UNWRAP: Manage Brackets with Ease

These two commands are invaluable when working with bracketed structures like XML or mathematical formulas:

STR.WRAP: This command adds brackets around a specified portion of your string, making it easier to manage structured data.

STR.UNWRAP: Conversely, this command removes brackets from a specified portion of your string, simplifying the data for further manipulation.

Comprehensive Set of BASIC-like Commands

In addition to these new commands, we continue to offer the complete set of traditional BASIC string manipulation commands such as RIGHT$, MID$, and LEFT$ in their SPR-Counterpart (STR.Mid To, STR.Left etc.). These are available both as functions and as statements, providing you with the flexibility to choose the most suitable option for your specific needs.

Streamlined Output Handling in New String Functions
One of the standout features of our new string functions is their unique approach to output handling.
Unlike many other functions, these string functions are designed to return their results directly in the source variable if an output variable is not specified.

So do not look on TOS as with most other functions, there is often nothing there.

 

In-Place Modification: A Key Differentiator

This behavior is a significant departure from traditional functions that usually require a separate output variable. By allowing the result to overwrite the source variable, these new string functions offer a more streamlined and efficient way to manipulate strings.

 
Simplified Command Chaining

This feature also has the added benefit of simplifying command chaining. Since the output is returned in the source variable, you can easily chain multiple string functions together without having to manage multiple output variables. This leads to cleaner, more readable code.
This in-place modification capability is an important aspect to consider when using our new string functions, as it can significantly impact how you structure your code for string manipulation tasks.

 

 

About the older STR.-Functions

 

The following Text is only valid for the first bunch ob String Command that is listed below.

Below you will find a list/Set a set of String-Commands. You can use it mainly to change binary strings. For this, variables will only be resolved one time (binary compatible). specialfolders and systemvariables are will be evaluated, to prevent unwanted changes in binary data.

 

The command has several modes of operation. Each of these is like a separate command.

    CLONE - Mode. This Mode will create a new String. out of a second string. The result is a string, consisting of multiple copies of the second specified string.

    DELETE - Mode: Delete bytes/chars from inside the string.

    FIND - Mode: Search for a String inside a String. Result will be on TOS. String is NOT changed in this Mode.

    INSERT - Mode: This Mode will insert a String at a place into the Source String.

    OVERWRITE - Mode: This Mode will patch the Source String with a second Patch String. It will "overwrite" the Source String, while it will never change the total length of the String.

    PATCH - Mode: This Mode combines the DELETE and the INSERT Mode. Unlike the OVERWRITE-Mode, this Mode can change the length of a String.

    REVERSE - Mode: This will reverse all bytes in a String. The last byte will be the first byte.

    GENERATE RANDOM STRING - Mode: This will generate a random string from specified length and of specified characters.

    STR.CHARS A - OTP-PRNG. This CPRNG is based on the ANSI X9.17 standard for secure key generation and uses Rijndael as its cryptographic base algorithm.

    STR.CHARS B This is an enhanced version of CHARS A. It uses the same PRNG. This version will create between 10 and 20 Pads using CHARS A. Then all of these will be combined using the XOR.

    STR.CHARS C This CPRNG is based on the recursion-with-carry generator, invented by George Marsaglia. Estimated Cycle length is 3 x 10^47.

    STR.CHARS D This is an enhanced version of CHARS C. This version will create a Pad with the algo from STR.CHARS A  first. It will then created between 4 and 8 Pads using the algo from CHARS C. Then all of these Pads will be combined using the XOR to get a final result.

    STR.MAKE PAD MAKE PAD has the same Syntax like GENERATE RANDOM STRING - but uses internally another PRNG (Pseudo Random Number Generator) with a Periode length of about 2^60 which is in numbers (rough estimation) 1152921504000000000 before the sequence will repeat. Therefore the result should be safe for cryptographic uses.This Mode will generate a random String of specified length and from specified characters. You can use it to generate passwords.

    STR.FROM BASE64 URL will convert the MIME/BASE64 URL data that is contained in a variable, back to the original-Format. The result will be in the same variable or in a Target variable if given.

    STR.TO BASE64 URL will convert the text or binary data that is contained in a variable, to the BASE64 URL-Format. The result will be in the same variable or in a Target variable if given.

    STR.FROM HEXASCI will convert the HEXASCII-text that is contained in a variable, to the Original-Format. The result will be in the same variable or in a Target variable if given.

    STR.TO HEXASCI will convert the text or binary data that is contained in a variable, to the HEXASCII-Format. The result will be in the same variable or in a Target variable if given.

    STR.MIME TO TEXT will convert the MIME/BASE64 data that is contained in a variable, back to the original-Format. The result will be in the same variable or in a Target variable if given.

    STR.TEXT TO MIME will convert the text or binary data that is contained in a variable, to the MIME-Format. The result will be in the same variable or in a Target variable if given.

 

Timing considerations

 

' Timing considerations

: $$TIM=#dtime#

: $$TXT=A

: $$NUM=30000000

STR.CLONE|$$SRC|$$NUM|$$TXT

LEN.$$SRC|$$LEN

VAR.$$TIM=#dsince#

MBX.We cloned the A $tos$ times in: $$TIM seconds

 

stringcommandallgemeinb1

 

To generate a string of 29.3 MB we needed about 1 second. The times on different systems may vary, the times on my testing systems are only to give you a rough idea.

 

Now the STR.PATCH is possibly our slowest operation. Let's see how slow it is.

 

VAR.$$NEW=BB

VAR.$$POS=4

VAR.$$DEL=0

VAR.$$TIM=#dtime#

STR.PATCH|$$SRC|$$POS|$$DEL|$$NEW

VAR.$$TIM=#dsince#

LEN.$$SRC|$$LEN

MBX.We patched it in $$TIM$crlf$New Len=$$LEN

 

graphic

 

We needed 0.3 of a second to patch the 29 MB String. Now let's see how much it would be if we use STR.OVERWRITE.

 

VAR.$$TIM=#dtime#

STR.OVERWRITE|$$SRC|$$POS|$$NEW

VAR.$$TIM=#dsince#

MBX.Overwrite took: $$TIM

ENR.

 

graphic

 

Looks like there is no large difference in practical use.

Finally let's reverse that string and look how long it takes.

 

VAR.$$TIM=#dtime#

STR.REVERSE|$$SRC|$$POS|$$NEW

VAR.$$TIM=#dsince#

MBX.Reversing the 29 MB took: $$TIM

 

graphic

 

Seems not to be a big deal. Looks like you can make ten times that in a second.

This should give you a rough approximation of execution times of these String commands.

 

Lets end with something simple.

Let's revers a string with just 500 bytes and measure this.

 

VAR.$$TIM=#dtime#

STR.REVERSE|$$SRC

VAR.$$TIM=#dsince#

MBX.Reversing the 500 Byte took: $$TIM

 

graphic

 

In other words: 0.016 seconds. You can do that 62 times in a second.

 

 

 

General Hints:

To Replace bytes in a String, use the RPL. - RePLace in String command.

To extract a part out of a String, use the GSS. - GetSplitString command.

If your String is a delimited String (like a .csv-file), use:

 

    SBD. - String between Delimiter

    SBM. - String between Delimiter-Multiple

 

To filter a String, use: GFS. - Get-Filtered-String.

 

 

 

 

Syntax

 

STR.P1[|P2][|P3][|P4]

 

 

Parameter Explanation

 

P1 - MODE of operation

 

P2 - Source and (if no P2) destination variable

 

P3 - numeric parameter, will be completely resolved

 

P4 - depend on the Mode of operation

 

 

 

Example

 

'*************************************

' STR.

'*************************************

VAR.$$SRC=Alles alt macht der Mai!

VAR.$$NEU=Neu

VAR.$$ALT=alt

STR.FIND|$$SRC|1|$$ALT

VAR.$$POS=$tos$

DBP.Patching at: $$POS

STR.OVERW|$$SRC|$$POS|$$NEU

DBP.$$SRC

ENR.

 

 

Remarks

 

Variables inside the source are only resolved once. Therefore it can be safely used fort for Binary data. Specialfolders and systemvariables etc. are not resolved, to avoid unwanted changes in binary data..

 

 

 

Limitations:

 

-

 

 

See also:

 

    1.5.2 Working with Text-Strings

    VAR. - Variable Set Value/Clear

    VAS. - Variable with String

    RPL. - RePLace in String

    IVS. / NVS. - If-Variable-String

    GSS. - GetSplitString

    GES. - Get-Extracted-String

    GFS. - Get-Filtered-String

    SBD. - String between Delimiter

    SBM. - String between Delimiter-Multiple

    FEM. - For Each Member

    LEN. - Length-of-String