EDIT: String operations of all kinds in one single statement (H+)

⇒Home ⇒Contents ⇒more on Strings
(⇒Optional Keywords Syntax)

Bookmarks:
  ⇒append separator and string   ⇒copy_string   ⇒count_occurences   ⇒delete_substring   ⇒insert_string   ⇒lexical commands   ⇒lowercase_string   ⇒parse_string   ⇒remove double entries   ⇒replace string   ⇒search options   ⇒sort string commands   ⇒string edit error control   ⇒tabify string   ⇒uppercase_string

Optional keywords:
APpendTo Begin ContInueiF CoPyTo Count Delete DO ELSE End ENDIF ERror EXit GetPosition IF inLeXicon Insert ITeM Left LeXicon LowerCase Mark1 Mark2 Marks Option Parse RaNge RangeBegin RangEend RePLaceby Right ScanFor ScanForLeft ScaNnot ScaNnotLeft SePaRators SetPosition SorTColumn1 SortDelDbls SorTedtext SortFromIndex SorTtoIndex TabiFyfont Text UpperCase Word WordEnd
keyword type mini example

Keywords to change or remember the actual location Loc

:

Right

txt r=$CR move Loc right to next $CR
  • n = EDIT(T=sample, Option=2, Right="jump", Ins="X")
  • ! n=0: the word "jump" was not found
[1] r=72 move Loc right 72 bytes

Left

txt l=$TAB move Loc left to next $TAB
[1] l move Loc left 1 character

Begin

--- b set Loc to 1st nonblank in string

End

--- e set Loc to byte after last nonblank in string
  • EDIT(T=sample, End, Left, Parse=LastNonBlank)
  • ! LastNonBlank is now "g" (no M1, M2 set)

Mark1

--- M1 remember start position for parse/delete/replace/copy string
  • both M1 and M2 are reset to 0 after a Parse, Delete, Insert, CopyTo, APpendTo, or RePLaceby

Mark2

--- M2 remember end position for delete/replace/copy string Mark2

Word

num word=n set Loc to 1st byte of n-th word right (n>0) or left (n<0) of current word. For n=0 Loc is set to the 1st byte of current word. Word boundaries can be adjusted by SePaRators

WordEnd

txt we implicitely set Mark1 and Mark2 to 1st and last byte of current word. If txt is set it will be a separator for the APpendTo command.

GetPosition

NUM gp=j
vec gp=pVec pVec(DOindex) is set to byte location
  • DIMENSION vec(10)
  • EDIT(T=sample, Right=" ", GetPosition=vec, Right, DO=10)
  • ! vec is set to (4, 10,16, 20, 26, 31, 35, 40, 44, 0)

SetPosition

num sp=j set byte location to Loc>0 and Loc<=LEN(string)
  • EDIT(T=sample, SetPosition=13, Insert="XXX")
  • ! The quick brXXXown fox jumps over the lazy dog
vec sp=pVec move Loc to pVec(DOindex)

ScanFor

txt sf=".:!" scan right for next "." or ":" or "!"
  • n = EDIT(T=sample, ScanFor="jump", Ins="*", Right=2, DO=10)
  • ! "The q*uick brown fox *j*u*m*ps over the lazy" (truncated)

ScaNnot

txt sn="123" scan for next byte that is nor 1 or 2 or 3

ScanForLeft

txt sfl="xy" scan backward for next x or y

ScaNnotLeft

txt snl=" " scan backward for next non-blank

ITeM

num itm=5 set Loc to item start (count SePaRators hits)
  • EDIT(T=sample, SePaRators="abc", ITeM=2, Insert="<", ITeM=3, Insert=">")
  • ! The quic<k brown fox jumps over the la>zy dog

RaNge

txt RN=$CRLF repeat all in ranges 1...$CRLF...$CRLF.., each new range also restarts DO
  • EDIT(T=sample, RaNge=" ", Del=1)
  • ! he uick rown ox umps ver he azy og
num RN=4 character ranges 1..4 5..8 9..12 ..
  • EDIT(T=sample, RaNge=4, RangEend, Insert=".")
  • ! The .quic.k br.own .fox .jump.s ov.er t.he l.azy .dog

RangeBegin

--- rb set Loc to begin of range
txt rb="SUBR" MOVE SCRIPT to next "SUBR", Count=lineNR and/or Option=... may follow)

RangEend

--- re Loc to end range (string end if no range)

Keywords to change the original string:

Delete

--- d

delete_substring

(m1:m2) if m1,m2 are set
  • EDIT(T=sample, Ri="x", M1, Ri="y", M2, Del)
  • ! sample is now "The quick brown fo dog "
txt d=" " move Loc to next " " and delete this blank
num d=3 delete 3 characters starting at current location Loc

Insert

txt i=$CRLF

insert_string

$CRLF at Loc.
Note: Characters exceeding the length of string are dropped

RePLaceby

txt rpl="x"

replace string

: after either of Right, Left, ScanFor, ScanForLeft, ScanNot, ScanNotLeft, or M1 and M2
  • EDIT(T=sample, ScanFor="aeiou", RePLaceby="*", DO=5)
  • ! sample="Th* q**ck br*wn f*x jumps over the lazy dog "

UpperCase

[1] uc=3

uppercase_string

: capitalize 3 characters
  • EDIT(T=sample, RaNge=" ", UpperCase=2)
  • ! THe QUick BRown FOx JUmps OVer THe LAzy DOg

LowerCase

[1] LC

lowercase_string

character at actual location

TabiFyfont

txt TF=3

tabify string

:
  • replaces all doubleblanks in string by 1 or more tabs to allow for aligned table columns.
  • FontNr=3 is the current dialog font (see Options menu > Fonts).
  • Use RaNge=line_sep ( normally $CRLF)
  • EDIT(T=multi_line_string, RaNge=$CRLF, TabiFyfont=3)

Keywords to extract information

:

Parse

txt p=subtxt

parse_string

to individual substrings:
M1>0: subtxt + string(m1:Loc) share memory
  • EDIT(T=sample, Right="e", Mark1, Right="i", Parse=xyz)
  • ! xyz == ""e qui" shares memory with sample
M1==0: string(>= Loc), free of SePaRators
  • EDIT(T=sample, R="r", Parse=word1, P=word2, p=w3)
  • ! word1=rown, word2=fox, w3=jumps
moves Loc to next SePaRator

CoPyTo

TXT cpt=word

copy_string

set word to string(m1:m2) if m1 and m2 are set

APpendTo

TXT apt=str

append separator and string

to the variable str. Default separator is a blank, it can be changed with WordEnd=new_separator

Count

--- c

count_occurences

:
default count start position is = 1
num c=byte1 set count start position to byte1
txt c=txt n=txt"s in string(start:Loc), NOTE: set Loc to the end position, e.g. End!
  • n = EDIT(T=sample, End, Count=" ") ! n = 9 blanks

Keywords to control command execution

Option

num o=1

search options

: case=1, word=2, scan=8, trailing blanks=16, best match=32, verify=64, RegEx=128. For examples click here.

SePaRators

txt spr=".!" default is " .,(+-*/^;="\<>!:)", bar, $CR, $LF, RangeBegin, RangeEnd
num spr=d separate string in d bytes for sorting etc

DO

num do [=n]
  • loop over all EDIT arguments maximum n times
  • DO without argument stops to loop when an error occurs
  • the loop is terminated when an error occurs
  • Tip: error provocation can be useful, e.g. write "Right=2,Left" instead a simple "Right" will stop the loop at the last non blank character
  • RaNge can sometimes be preferable to DO. RaNge may also be combined with DO.
  • EDIT(T=sample, Right=" ", Ins="X", DO=10)
  • ! Loc unchanged: TheXXXXXXXXXX quick brown fox jumps over the

IF

--- IF, R=8 next commands up to ELSE or ENDIF only if R=8 OK
  • EDIT(T=sample, IF, Right="XY", End, Insert=" XY OK", ELSE, End, Insert=" NO XY")
  • ! The quick brown fox jumps over the lazy dog NO XY
txt IF="@" continue (max to ELSE ) only if string(loc) == @

ELSE

[T] ELSE next commands only if error after IF

ContInueiF

txt cif="az" next keyword only IF a <= string(loc) <= z

ENDIF

--- endif closes IF..ELSE... clause if needed

EXit

[T] ex exit range scan

ERror

LBL er=99 (on error jump to label 99)

lexical commands

LeXicon

txt lx=txt
  • scan string for the 1st lexical item in txt.
  • The result n is the item nr found.
  • Lexical items in txt must be separated and terminated by one of the current SePaRators.
  • n = EDIT(T=sample, LeXicon="cow,dogg,fox,") ! n=3
$

Marks

txt $m="<>"
  • 2 characters to embrace the lexical items in string found by inLeXicon.
  • Default is $Marks="$" to mark the item begin without a mark at the item end.
$

inLeXicon

txt $lx=txt
  • This option marks all substrings in the Text=string that are also in txt. The mark is a "$" or the 2 embracing characters set in $Marks.
  • By default only the item begin is marked by a "$" without end mark.
  • With the Option keyword, case and word etc can be set.
  • The SePaRators keyword determines word separators.
  • Blank strings are not marked, independent of the Option setting
  • EDIT(T=sample, $Marks="[]", $inLeXicon="cow,dog,fox,")
  • ! The quick brown [fox] jumps over the lazy [dog]

sort string commands

SorTtoIndex

num sti=vec indices of sorted words goes to vec
  • EDIT(T=sample, Option=1, SorTtoIndex=vec)
  • ! vec -> (3,9,4,5,8,6,2,7,1,0) with Option=1 (keep case)

SorTedtext

txt st=lex
  • lex gets sorted

    words

    (words are defined by current setting of SePaRators) or

    n-byte chunks

  • with SePaRators=$LF:

    sort lines

    (the EDIT-string can be a complete file).
  • with SePaRators=n: string is sorted in n-byte chunks
    • EDIT(Text=sample, SePaRators=1, SorTedtext=sortedSample)
    • ! " Tabcdeeefghhijklmnoooopqrrstuuvwxyz"
  • Without Option=1+...(keep case) the EDIT-string will be lowercased
    • EDIT(T=sample, SorTedtext=sample)
    • ! brown dog fox jumps lazy over quick the the
  • With Option=...+ 4+...(backward) Sort will be descending
    • EDIT(Text=sample, Option=4+1, SorTedtext=sample)
    • ! the quick over lazy jumps fox dog brown The

SortDelDbls

txt sdd=lex lex is sorted,

remove double entries

  • EDIT(T=sample, SortDelDbls=sample)
  • ! brown dog fox jumps lazy over quick the

SortFromIndex

num sfi=vec sort words in string along vec (no lower case conversion)
  • vec = (2, 1, 4)
  • EDIT(T=sample, SortFromIndex=vec, SorTedtext=sample)
  • ! sample is now "quick The fox"

SorTColumn1

num stc1=2 sort starts in word positions 2 (disregard 1st character)
  • EDIT(T=sample, SorTColumn1=2, SorTedtext=sample)
  • ! lazy the the dog fox brown quick jumps over

©2000-2010 Georg Petrich, HicEst Instant Prototype Computing.
All rights reserved.
Impressum