Jump to content
Sign in to follow this  

cant replace 2 Different Strings in Array

Recommended Posts


Hi i have following array:


Now i want to check 

Pseudo code:

StringInStr salutation === firstname 

then Replace the Firstname in Salutation with nothing



Hall Herr Albeck

After replace

Hallo Herr, 

same with lastname


Current Code its half working but only for one firstname or lastname and not together 

Func Main()

    Local $sAdr = @ScriptDir & "/rsg_mailing.csv"
    Local $h = FileOpen($sAdr, 0)

    Local $aRet = _CSV2Array($h, Default, True, 1)


    For $i = 0 To UBound($aRet) - 2

        $i = $i + 1

;Bekomme Vorname
        $checkFirstName = $aRet[$i][1]
        $lastName = $aRet[$i][2]

        $salutation = $aRet[$i][3]
        If (StringInStr($salutation, $lastName)) Then
            $test = StringReplace($aRet[$i][3], $lastName, "")
            ;Replace Lastname with nothing
                $aRet[$i][3] = $test
                ConsoleWrite($test & @LF)


    If (StringInStr($salutation, $checkFirstName)) Then
                $replacefirstName = StringReplace($aRet[$i][3], $checkFirstName, "")
                $aRet[$i][3] = $replacefirstName
                ConsoleWrite($replacefirstName  & @LF)
        ;ConsoleWrite($checkFirstName & @LF)


EndFunc   ;==>Main

ouput from this code:



Edited by cannaper

Share this post

Link to post
Share on other sites

It looks to be working to me. I can't test it on the system I'm on right now. Why are you adding 1 to $i?

$i = $i +1

Do you really intend to skip past every other row?

Edited by czardas

Share this post

Link to post
Share on other sites

thx i removed the +1 now its woring!  idk why i added this xD

  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.