Name swap

Posted on 2009-12-24
Last Modified: 2012-05-08

I want to swap Cust2 to be Cust1 only if "|" is not blank.

plse see sample

Cust1                 Cust2
jim johnson      | Tim smith | jim johnson
David Williams | Mike Rodriguez |
Sam Red           | Mark Green | Sam Red

result like this

Tim smith | jim johnson
David Williams | Mike Rodriguez
Mark Green | Sam Red
Question by:VBdotnet2005
    LVL 37

    Expert Comment

    Is this a single string expression?
    LVL 51

    Expert Comment

    what does this mean? "only if "|" is not blank"
    LVL 83

    Accepted Solution

    Dim Names as String() = "jim johnson      | Tim smith | jim johnson ".Split("|")
    For I as Integer = 0 to Names.Length - 1
          Names(i) = Names(i).Trim()
    Dim NewName as string
    If Names.Length >2
       If Names(0) = Names(2) Then
          NewName = Names(1) & "|" & Names(0)
       End If
    End If
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    You haven't really specified the context of where this replace is to take place.  Are you reading in value from a file and outputting the results after the swap? Are you replacing text in the code window? Are you swapping columns of text inside a control?

    Please elaborate.  :)

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now