Sign in to follow this  
Followers 0
cannaper

cant replace 2 Different Strings in Array

3 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

1 person likes this

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  
Followers 0