Jump to content

cant replace 2 Different Strings in Array


Go to solution Solved by czardas,

Recommended Posts

Hi i have following array:

Image%202014-06-20%20at%2012.36.28%20PM.

Now i want to check 

Pseudo code:

StringInStr salutation === firstname 

then Replace the Firstname in Salutation with nothing

example:

Salutation:

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)

    FileClose($h)
    _ArrayDisplay($aRet)

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

        $i = $i + 1

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

;Salutation
        $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)


        EndIf

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

    Next

    _ArrayDisplay($aRet)
EndFunc   ;==>Main

ouput from this code:

Image%202014-06-20%20at%2012.40.39%20PM.

greetings

Edited by cannaper
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...