Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 3 of 3

Thread: Syntax

  1. #1
    Administrator tommy's Avatar
    Join Date
    Nov 2001
    Location
    Copenhagen
    Posts
    4,270

    Default

    Syntax (following is examples of expressions)





    access a field in a file:

    xxx in $file



    access a variable

    $x



    access first element in an array

    1 in $x

    $x[1]



    find position in a string

    index("@", email in $file)



    find character(s) in field

    index("@", email in $file)<>0



    is a . comming after @

    index(".", substr(email in $file,1, index("@",email in $file)))<>0



    the last 5 characters of $x

    substr($x,lng($x) - 5)



    is the 3. and 4. characters "DE" ?

    substr($x, 3,2)="DE"



    insert an element in an array

    $x=insert($x,1,1,"oli")



    delete first element of an array

    $x=delete($x,1)



    delete the last element of an array

    $x=delete($x, lng(denull($x)))



    is $x empty (NULL) ?

    null($x)

    $x=NULL



    length of string (character) ?

    lng($x)



    length of an array (array of character) ? (warning length is not exact)

    lng(str($x))



    does a file contain any numbers=

    index("1", translate(____ in $file, "23456789","11111111"))=0



    remove all numbers from a field

    strrep(translate(____ in $file,"12345678790","1111111111"),"1","")



    Something really complicated :smile:

    x $x=""; for $i=1 to lng(val(substr(translate(str($file),"[]"," "), index("=",str($file)) +1 ),8)) do (if type(nullsub($i in $file,"")) isin {1,2} then ($x=$x + " " + nullsub(str($i in $file) + "," , ", ")))



    does a string only contain numbers ?

    $oli=str(nullsub(val($oli,1),""))



    does a string only contain allowed characters ?

    lng(strrep(translate($oli,"0123456789/","***********"),"*",""))=0



    is the string ending with ".de", ".net" or ".com" ?

    d substr(substr($x, index("@", $x) + 1), index(".",substr($x, index("@", $x) + 1))) isin {".de", ".com", ".net",}



    reverse the string

    x $y="";for $i = 1 to lng($x) do ($y=$y + substr($x, lng($x) - $i + 1,1))



    on a dbdict - get all fieldsnames (type 1 or 2) seperated with semicolon

    x $x="";for $y=1 to lng(1 in$dbdict) do (if 4 in $y in 1 in $dbdict isin {1,2} then ($x=$x+nullsub(strrep(1 in $y in 1 in $dbdict," ","")+";","")))



    looking for a .com or .net at the end of a string

    index(substr($x, lng($x) - 3), {".com",".net"})~=0 "bla bla bla: "+str($x)+name in $file+substr(evaluate(parse("$x+=1", 11)), 1, 0) val(str($x) + substr(evaluate(parse("$x+=1", 11)), 1, 0)) in {"First one","2nd","3rd"} val(str($x) + substr(evaluate(parse("$x+=1;$y={\"a\",\"b\"}", 11)), 1, 0)) in $y


  2. #2
    Junior Member
    Join Date
    Jul 2009
    Posts
    9

    Default

    Hi tommy nice work done keep pasting such rich info here i know you have learned all this with lot of practice and experince but still I hope you will keep these rich articles posting here

  3. #3
    Senior Member fid509's Avatar
    Join Date
    Feb 2002
    Location
    Brussels
    Posts
    380

    Default

    I like the power of regular expressions if I have the check for certain strings:

    I wrote a genaral function RegularExpressionMatch inside a ScriptLibary

    Code:
    /*****************************************************************************************************
    *  This function will match a string to a regular expression.
    *  Author: fid509
    *  Date: 09/07/2009 
    *  @input  {sString,regex} sString:the string to be tested, regex: the regular expression to use
    *  @output {boolean} true or false to indicate the string matched the regular expression
    *
    /****************************************************************************************************/
    
    function RegularExpressionMatch(stringToCheck,expression){
    
    if (stringToCheck.match(expression)) {
            //print("Valid string");
            return true;
            }
    else {
            //print("Invalid string !");
            return false;
            }
    
    }
    Then I can use this function for example in a formatcontrol to set a variable used later on in validations.

    Code:
    //Check if field gdcode contains a string matching the pattern G9999D999
    var re="/^[Gg]{1}\d{4}[Dd]{1}\d{3}$/";
    re = eval(re);
    
    if (system.library.FunctionsGlobal.RegularExpressionMatch(system.vars.$file.gdcode,re)) {
            system.vars.$validGDcode=true;
            //print("Valid GD code");
            }
    else {
            system.vars.$validGDcode=false;
            //print("Invalid GD code !");
            }

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts