Replace a text in a Field

niimodinniimodin Member Posts: 142
Hello Experts,

I have a client who has a customized module which creates a field for batch nos in the Item table.

I use to update is using dataport.

I am finally handing over the system to the client and what to design a simple where the client can click a button and the system is updated

for example: I want to replace all : 09C/_ with 10D/_ in the item table.

What function should I use?

Can someone help me

Thanks

Comments

  • superjetsuperjet Member Posts: 40
    check out in Help STRPOS (String) function..
    Use this function to search for a substring inside a string.
  • JedrzejTJedrzejT Member Posts: 267
    edited 2009-12-15
    maybe it is not what you are looking for.. Simplest way without the code is - user hit CTR+H (replace) on list form and use it like in any other application. List form must be editable.. at last for this field

    If You like to use function then use some filter, loop table and replace what you have to replace
  • niimodinniimodin Member Posts: 142
    Hello,
    Thank you very much.
    How do I loop through the data.
    I am replace all items in the data
    Thanks
  • matteo_montanarimatteo_montanari Member Posts: 189
    JedrzejT wrote:
    CONVERTSRT(StringVariable,'09C/_','10D/_');
    edit..
    maybe it is not what you are looking for.. Simplest way without the code is - user hit CTR+H (replace) on list form and use it like in any other application. List form must be editable.. at last for this field

    If You like to use function then use some filter, loop table and replace what you have to replace, You can use CONVERTSR if this only part of string you want replace.

    Hi

    CONVERTSRT use second and third parameter like a mask, non a search text.

    If the string is '09C/_0999' you will obtain '10C/_1000'...

    The best solution is to use strpos to find the position of the substring, and do a DELSTR and next INSSTR.

    bye

    Matteo
    Reno Sistemi Navision Developer
  • JedrzejTJedrzejT Member Posts: 267
    IF rec.FINDSET THEN
      REPEAT
    
      UNTIL rec.NEXT=0
    

    for example, but.. if You don't know this one I think you should read app. designer guide to know what you are doing

    Eto: thanks - i know that.. just made a mistake :whistle:
  • SkordasSkordas Member Posts: 1
    since i was working on a real str_replace function here my solution
    STRREPLACE(haystack : Text[1024];needle : Text[1024];replace : Text[1024]) : Text[1024]
    
    i := STRPOS( haystack, needle );
    IF ( i > 0 ) THEN BEGIN
    
      // clear first needle in haystack
      haystack := DELSTR( haystack, i, STRLEN( needle ) );
    
      // return previous + replace + rest
      EXIT( COPYSTR( haystack, 1, i - 1 ) +
        replace +
        STRREPLACE( COPYSTR( haystack, i, STRLEN( haystack ) - i + 1 ), needle, replace ) );
    
    END; // needle found
    

    avoids to replace any already replaced values who contain the needle again. \:D/
  • ajhvdbajhvdb Member Posts: 672
    Thanks for sharing. The previous stringreplace function i found was running forever if you replaced "needle" by "needle two".. ](*,)
Sign In or Register to comment.