1. Starting Guide

<< Click to Display Table of Contents >>

Navigation:  1. Starting Guides >

1. Starting Guide

1.5.1.4. Using Text-Strings

Previous Top Next


Starting Guide

 

BASIC String Operations

How do you work with string-data?

 


 

Adding string

 

That is a very basic issue. We have two strings and we want to add them to one string

We have already done that in the example above. Adding strings is as easy as writing their variable names one after the other.

 

: $$TXA=Hello

: $$TXB= world!

: $$TXT=$$TXA$$TXB

DBV.$$TXT

 

The output is as expected:

 

graphic

 

 

Are there any size limit for strings?

 

Generally there is a 32-bit size limit that limits string sizes to 2 GB. In real life the limits depend on your system, on the fragmentation of your memory. The limit will be less because string memory must be sequential. 500 MB should be no problem, if your RAM allows it even more. Note that the larger strings become, the slower the string operations may get.

 

: $$TXT=This text is going to be very large.

FOR.$$MUC|1|22

 VAR.$$TXT=$crlf$ $$TXT $crlf$ $$TXT

NEX.

LEN.$$TXT|$$SIZ

DBP.$$SIZ

DMP.1

MBX.READY

ENR.

 

This script is going to concatenate a string of Size ~180 MB. Once we are adding up 40 MB and more, it will start to get a bit slower.


 

Subtracting / Splitting strings

 

We have a string, but we do only need a part of it. There are many such cases in real life.

For example you get a phone number from a list or file. Or from a text-box.

 

: $$TXT=07247/9851112

GES.f|$$TXT|/|$$RES

DBP.Predial is: $$RES

GES.h|$$TXT|/|$$RES

DBP.Number is: $$RES

ENR.

 

The output will be:

 

[10] Predial is: 07247

[12] Number is: 9851112

 

What, if we do not know how the number is written?

It may be like this:

 

: $$TXT=(07247)9851112

' Will split thestring at ANY of the given characters

GES.f|$$TXT|)/|$$RES

' removes left and right of $$TXT all of the given characters

VBT.$$RES|()/

DBP.Predial is: $$RES

 

The output will be as expected:

 

[10] Predial is: 07247

 

Let us try something else. We have now the Pre-Dial and we just want the first two characters of it into a variable.

 

' We define our string

: $$TXT=07247

' We want character 1 to 2 from $$TXT into $$RES

GSS.1|2|$$TXT|$$RES

DBP.Predial is: $$RES

 

The output will be:

[9] Predial is: 07

 

Now we want the last three characters from our string.

 

' We define our string

: $$TXT=07247

' We want the last three characters from $$TXT into $$RES

GSS.-3|-1|$$TXT|$$RES

DBP.Predial is: $$RES

 

The output will be:

[11] Predial is: 247

 


 

Get and set ASCII-values

 

Next we want to get an ASC-Values of one of the characters.

 

: $$TXT=07247

ASC.$$TXT|$$RES|1

DBP.The ASC-Value of Character 1 is: $$RES

 

The output will be:

[11] The ASC-Value of Character 1 is: 48

 

Next we want to put an ASC-character into a variable. This way you can add any international character to an variable, even if you may not easily find it on your keyboard.

 

: $$ASC=99

CHR.$$ASC|$$RES

DBP.The Character of ASC-Value $$ASC is: $$RES

 

Now lets take a look on string based decisions.

 


 

String-based decisions

 

We have a string for example from a command-line-parameter and if it contains the sequence /u we want to do something different in our script.

 

We do it like this:

 

' To really get the command-line of a compiled Script-exe

' we would use this:

' VAR.$$CMD=$cmdexe$

' As we run it from the Editor, we use:

VAR.$$CMD=parameter is /q etc.

VAR.$$STR=/q

IVC.$$CMD=$$STR

 DBP. We do it different

ELS.

 DBP.We do it normal

EIF.

STS.DUMP

MBX.Ready

 

As you can see, IVC. will also place the position where it has found the string on to the TOS.

 

Besides checking if a string is inside another, we can do basic string compare using IVS. / NVS. - If-Variable-String .

 

VAR.$$CMD=/q

VAR.$$STR=s/q

IVS.$$CMD=$$STR

 DBP. We do it different

ELS.

 DBP.We do it normal

EIF.

 

IVS. and IVC. contain many more options then i have shown in these examples.

Take some time and try these commands yourself. Experimenting is the best way to get experience.

 


 

Debugging/dumping all used variables

 

You can DUMP all currently used variables using the DMP.-Command.

 

' Dump Global Variables

DMP.2

MBX.Ready?

ENR.

 

' Dump Local Variables

DMP.3

MBX.Ready?

ENR.

 

For more Details see the DMP. Command.

 

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

    GFS. - Get-Filtered-String

    GES. - Get-Extracted-String

    SBD. - String between Delimiter

    SBM. - String between Delimiter-Multiple

    FEM. - For Each Member

    LEN. - Length-of-String