String Issue

vikram7_dabasvikram7_dabas Member Posts: 611
I have created one variable of Data Type Code and Length 20,I want to know that whther in the end of this string any numeric value consist or not.Is it possible?If yes then How can I do this?
Vikram Dabas
Navision Technical Consultant

Comments

  • JedrzejTJedrzejT Member Posts: 267
    edited 2008-07-29
    maybe there is someting shorter, maybe not :whistle:
    IF COPYSTR(StrVar,STRLEN(StrVar)) IN ['0','1','2','3','4','5','6','7','8','9'] THEN
      MESSAGE('Has numeric at the end')
    ELSE
      MESSAGE('Hello world');
    
  • McClaneMcClane Member Posts: 40
    i:=strlen(YourCode);
    while YourCode[i]in['0'..'9']do
      begin
        YourNumCode:=format(YourCode[i])+YourNumCode;
        i-=1;
      end;
    
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    Int
    var
    integer
    CodeString -- var --
    code
         IF (EVALUATE(Int,COPYSTR(CodeString,STRLEN(CodeString),1))) THEN
           MESSAGE('has an integer at last')
         ELSE
           MESSAGE('Does not have an integer at last')
    
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • XypherXypher Member Posts: 297
    I haven't tested this function yet but it should do the trick with whichever way you choose to implement.
    GetEndStrNum(StrVar : Text[1024];VAR EndNumVar : Integer) : Boolean
    
      CLEAR(EndNumVar); //Prevent any mistake with a possible, previously, stored value
    
      StrVarClean := DELCHR(DELCHR(StrVar,'<'),'>'); //Remove any trailing spaces
      StrLenVar   := STRLEN(StrVarClean);
    
      IF StrLenVar = 0 THEN
        EXIT(FALSE);
    
    //****Use this if you know your strings will have a SINGLE digit end****
      IF StrVarClean[StrLenVar] IN ['0'..'9'] THEN BEGIN
        EndNumVar := (StrVarClean[StrLenVar] - 48);
        EXIT(TRUE);
      END ELSE
        EXIT(FALSE);
    //**********************************************************************
    
    //***And this if you know your strings can contain MULTI-digit ending***
      FOR i := StrLenVar DOWNTO 1 DO
        IF NOT (StrVarClean[i] IN ['0'..'9']) THEN
          IF EVALUATE(EndNumVar, DELSTR(StrVarClean, 1, i)) THEN
            EXIT(TRUE)
          ELSE
            EXIT(FALSE);
    //**********************************************************************
    
  • idiotidiot Member Posts: 651
    I have created one variable of Data Type Code and Length 20,I want to know that whther in the end of this string any numeric value consist or not.Is it possible?If yes then How can I do this?

    Try this:
    MESSAGE ('End of String is numeric? ' + FORMAT (Variable[STRLEN (Variable)] IN ));

    Think the shortest coding so far & fits the exact requirements :lol:
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
Sign In or Register to comment.