Using multiple parameters in STRPOS

samemery
samemery Member Posts: 60
Hi,

I am trying to find the first occurrence of a letter in a certain string.

FIRSTLETTEROCCURRENCE := STRPOS(STRING,'ABCDEFGHIJKLMNOPQRSTUVWXYZ');

However this is looking for that long string and not the letters individually.

Is there any way to use the STRPOS function to look for any occurrence of any letter?

Thanks.

Comments

  • Purvesh_Maisuria
    Purvesh_Maisuria Member Posts: 71
    Hello samemery,

    Try This,

    FIRSTLETTEROCCURRENCE := STRPOS('ABCDEFGHIJKLMNOPQRSTUVWXYZ','F');

    It Will Gives U 6, That is the First Occurance of Character 'F'.

    Thanks & Regards,
    Purvesh Maisuria.
  • lvanvugt
    lvanvugt Member Posts: 774
    Coincidence that Gaspode wrote this blog?

    Regular Expressions in NAV
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • PeterD
    PeterD Member Posts: 66
    Try something like this:
    String := '01234ADEFESDFG5KASDF6789';
    TempString := CONVERTSTR(String, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '--------------------------');
    FirstLetterOccurence := strpos(TempString, '-');
    
  • Purvesh_Maisuria
    Purvesh_Maisuria Member Posts: 71
    Hi PeterD,

    I Go thru ur solution, its working fine, thanks for focusing on new solution. But its working for fix length of CONVERTSTR's 2nd & 3rd Argument, if 2nd and 3rd Args length is differ than it is not working, so developer must have to write code for put same length of '-' as 2nd Argument of CONVERTSTR's Function. But Good to know new technique.

    Thanks & Regards,
    Purvesh Maisuria.
  • PeterD
    PeterD Member Posts: 66
    If you want to find the first letter in a string, the 2nd & 3rd argument will always be 26 characters. Or if you want to include lower case 52 characters. No need to write code to adjust 3rd argument to the 2nd.

    Or am I missing something :?:
  • MBerger
    MBerger Member Posts: 413
    PeterD wrote:
    If you want to find the first letter in a string, the 2nd & 3rd argument will always be 26 characters. Or if you want to include lower case 52 characters. No need to write code to adjust 3rd argument to the 2nd.

    Or am I missing something :?:
    If you want to include the lowercase characters, just use UPPERCASE() around the string to search in.
  • samemery
    samemery Member Posts: 60
    I used

    String := '01234ADEFESDFG5KASDF6789';
    TempString := CONVERTSTR(String, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '
    ');
    FirstLetterOccurence := strpos(TempString, '-');

    Worked perfectly. Thank you!!! \:D/