Problem

We want to replace a certain string inside another string by a new text. This is used, if you allow placeholders in string parameter input fields to be replaced by a scripted text. E.g. "»ID«", "»story«", "»date«"

Solution

We search (STRSTR) the position (posP) of the placeholder string, cut off the remaining ends by STRSUB and insert the new text.

Script

var="Hello »platzhalter«." !»» E.g. Input sring
suche="»platzhalter«" !»» placeholder for scripted text
ersetze="world" !»» Text to replace

posP=STRSTR(
var,suche)
IF posP THEN
  var=STRSUB(var,1,posP-1)+ersetze+
STRSUB(var,posP+STRLEN(suche),255)
  ENDIF

Script-Light

!*** aus ID substituieren

k=strstr(Quelle,"»aus ID«")
Ziel=strsub(Quelle,1,k-1)+GLOB_ID+strsub(Quelle,k+8,strlen(Quelle)-k-8+1)

Script-Multiple

!*** Platzhalter ersetzen
dim platz[],tausch[]
sts = REQUEST "AREA_DIMENSION", "",format)
platz[1]="»aus ID«" : tausch[1]=GLOB_ID
platz[2]="»Typ«" : tausch[2]=ZweiD
platz[3]="»Fläche«" : tausch[3]=str(format,a*b)+"m²"

for i=1 to maxPH
  k=strstr(Ziel,platz[i]) : langH=strlen(platz[i])
  while k and langH do
    Ziel=strsub(Ziel,1,k-1)+tausch[i]+strsub(Ziel,k+langH,strlen(Ziel)-k-langH+1)
    k=strstr(Ziel,platz[i]) : langH=strlen(platz[i])
    endwhile
  next i