English
Source / code snippets

4 new String-functions

 
- Page 1 -



RudiB.
have time one little with String-functions rumgebastelt.
here the Result:

FindCharAll

gives any positions the Zeichens / Zeichenkette from TestString$
appeal: FindCharAll TestString$,Suchzeichen/chain,leeres Int-aray
Return Value: aray with the positions in the string all found characters.

CountChar

counts any Suchzeichen/chain from TestString$
appeal: CountChar TestString$,Suchzeichen/chain
Return Value: Number of sought characters in the string.

FindLastChar

gives The position the last sought characters/chain in TestString$ on-
appeal: FindLastChar TestString$, Suchzeichen/chain
Return Value: position in the TestString

FindPosChar

find position the n.ten characters/Zeichenkette in the TestString$
appeal: FindPosChar TestString$,n.tes characters,Such_Zeichen$
Return Value: Postion the n.ten Zeichens/chain in the TestString.

here one small Testprogramm...
CLS
'command
'--------------
'findcharall(characters) >> aray - Number of characters / position the Zeichens in STRING
'findfirstchar(characters) >> position the zeichens in the STRING  --- How INSTR
'findlastchar(characters) >> position the last zeichens in the STRING
'findposchar(characters,z.B the 3.th characters in the STRING)
'countchar(characters) >> number the characters in the STRING
Declare TestString$,_Suchzeichen%[],Such_Zeichen$,z%,zaehler%,last&
TestString$="Im usual Dezimalsystem go The Digits 0 To 9 uses. in the Dualsystem against go numbers only with the Digits the Wertes zero and one displayed."
CLS
' find any characters/Zeichenketten in Teststring
Such_Zeichen$="f"
FindCharAll TestString$,Such_Zeichen$,_Suchzeichen%[]
Print "Befehl: FindCharAll"
Print
Print "gibt any positions the Zeichens / Zeichenkette from TestString$"
Print
Print "Aufruf -- FindCharAll TestString$,Such_Zeichen$,_Suchzeichen%[] (leeres aray)"
Print
Print "TestString :"+TestString$
Print "Suchzeichen is: -"+Such_Zeichen$+"-"
Print
Print
Print "Taste pressing...."
evaluate
Waitinput
CLS
' Zaehle any characters/Zeichenkette from Teststring
zaehler%=CountChar(TestString$,"e")
Print "Befehl: CountChar"
Print
Print "Zählt any sought Zeichens / Zeichenkette from TestString$"
Print
Print "Aufruf -- CountChar TestString$,Such_Zeichen$"
Print
Print "TestString :"+TestString$
Print "Suchzeichen is: "+"-e-"
Print zaehler%+ " time is the -e- in the Teststring include."
Print
Print
Print "Taste pressing...."
Waitinput
CLS
' find position for the latest characters/Zeichenkette in Teststring
zaehler%=FindLastChar(TestString$,"f")
Print "Befehl: FindLastChar"
Print
Print "gibt latest positions the sought Zeichens / Zeichenkette from TestString$"
Print
Print "Aufruf -- FindLastChar TestString$,Such_Zeichen$"
Print
Print "TestString :"+TestString$
Print "Suchzeichen is: "+"-f-"
print "das latest characters/Zeichenkette -f- is on position "+st$(zaehler%)+" in the Testsrting."
Print
Print
Print "Taste pressing...."
Waitinput
CLS
' find 3.tes characters/Zeichenkette in the TestString
zaehler%=FindPosChar(TestString$,3,"m")
Print "Befehl: FindPosChar"
Print
Print "Finde n.th characters/Zeichenkette in the TestString$"
Print
Print "Aufruf -- FindPosChar TestString$,n.tes characters,Such_Zeichen$"
Print
Print "TestString :"+TestString$
Print "N.tes characters is 3"
Print "Suchzeichen is: "+"-m-"
print "das 3.th sought characters/Zeichenkette -m- is on position "+st$(zaehler%)+" in the Testsrting."
Print
Print
Print "Für end Button pressing...."
waitinput
End
'--------------------------------------------------------------------------------------------

Proc CountChar

    Parameters _String$,_Zeichen$
    Declare _pos&,_zaehler&
    _pos&=0
    _zaehler&=0

    Whileloop LEN(_String$)

        _pos&=Instr(_Zeichen$,_String$)

        If _pos&>0

            Inc _zaehler&

        Else

            Break

        EndIf

        _String$=Right$(_String$, Len(_String$)-_pos&)

    EndWhile

    Return _zaehler&

ENDPROC

Proc FindCharAll

    Parameters _String$,_Zeichen$,_Char%[]
    Declare _pos&,_zaehler&,Array_zaehler&
    _pos&=0
    _zaehler&=0
    Array_zaehler&=0

    Whileloop LEN(_String$)

        Inc Array_zaehler&
        _pos&=Instr(_Zeichen$,_String$)

        If _pos&>0

            _zaehler&=_zaehler&+_pos&
            _Char%[Array_zaehler&]=_zaehler&

        Else

            Break

        EndIf

        _String$=Right$(_String$, Len(_String$)-_pos&)

    EndWhile

    Return _Char%[]

ENDPROC

Proc FindLastChar

    Parameters _String$,_Zeichen$
    Declare _Zeichen&[],_pos&,_Char%[],_zaehler&

    Whileloop LEN(_String$)

        _pos&=Instr(_Zeichen$,_String$)

        If _pos&>0

            _zaehler&=_zaehler&+_pos&
            _String$=Right$(_String$, Len(_String$)-_pos&)
            _pos&=0

        Else

            Break

        EndIf

    EndWhile

    Return _zaehler&

ENDPROC

Proc FindPosChar

    Parameters _String$,N_Zeichen&,_Zeichen$
    Declare _pos&,_zaehler&,Array_zaehler&,_Char%[]
    _pos&=0
    _zaehler&=0
    Array_zaehler&=0

    Whileloop LEN(_String$)

        Inc Array_zaehler&
        _pos&=Instr(_Zeichen$,_String$)

        If _pos&>0

            _zaehler&=_zaehler&+_pos&
            _Char%[Array_zaehler&]=_zaehler&

        Else

            Break

        EndIf

        If Array_zaehler&=N_Zeichen&

            Break

        Endif

        _String$=Right$(_String$, Len(_String$)-_pos&)

    EndWhile

    Return _zaehler&

ENDPROC

Proc evaluate

    z%=0

    Whileloop SizeOf(_Suchzeichen%[])-1

        inc z%
        print "Zeichen **"+mid$(TestString$,_Suchzeichen%[&loop],1)+"** Nr.:",z%,"An position: ";_Suchzeichen%[&loop]

    EndWhile

    ArrDel _Suchzeichen%[],0,SizeOf(_Suchzeichen%[])-1'Arraygrösse becomes on 1 staid.

ENDPROC

 
Xprofan X4
Rudolf Beske / München

Hardware: NB Intel I9 - 16GByte RAM
05/12/21  
 



« this Posting watts as Solution marked. »


p.specht

%matchpos and the n. Matching
=========================
Weils dazupasst, a Info of RGH from Sept. 2015 to right management the internen Variable %matchpos:
"%matchpos counts always from the actually Startposition from!
The following proc supply the desired n-case {'weitergeschaltete'} Verhalten":
Cls:font 2
var regstat&=get("regex"):set("regex",1)
var found&=0
var start&=0

Repeat

    found&=instr("([aA][bB][cC])","_abc_Abc_aBc_abC_defg_ABC",start&+1)
    case %matchpos<0:Break
    print %matchpos+start&,$match,%matchlen,"found& = ",found&
    start& = found&

until %matchpos=-1

set("regex",regstat&)'stood of before again settle
print "done."
waitinput
End
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/19/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

2.429 Views

Untitledvor 0 min.
Erhard Wirth06/14/24
Member 862464105/12/24
Uwe Starke11/17/23
ecki07/28/23
More...

Themeninformationen

this Topic has 2 subscriber:

p.specht (1x)
RudiB. (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie