1 Reply Latest reply on Feb 10, 2020 1:27 AM by Tim Beard

    How do I extract the first and second word given a string?

    Christopher Delaney

      Hello all, I have a text file in the format of [First Word] (space) [Second Word] (space) [Number]. I need to create two separate bubble plots of the frequencies of the first word for one bubble plot and the frequencies of the second word for the other bubble plot. How would I go about parsing apart the first and second words so that I can do this? This is my first time posting here, so apologies for any ambiguities.

        • 1. Re: How do I extract the first and second word given a string?
          Tim Beard

          Hi Christopher Delaney,

           

          My first thought was to use Regular Expressions and thought this might be a good learning opportunity for me, but then I opened your sheet. As all strings have the same format (as you described in your text), the easiest thing to do would be to go to the Data Source tab, click on the drop-down for the field, select Custom Split, enter Space as your separator, select Split off All and hit OK:

           

           

          The result in this case is your current field, plus (only) two new fields that you can rename to fit your needs:

           

          This might be sufficient for you. However, the delimiter between the second word and the number is a tab character, not space. To get the three fields you want, repeat the process with the third column above, but using a tab character as delimiter. To get the tab character into the dialog (as hitting tab just takes you to the next field in the dialog), open a simple text editor like Notepad, hit tab, highlight and copy it, then paste it into the Split dialog within Tableau. The result is:

          You might also want to look into the various string calculations within Tableau such as Split, just out of interest

           

          Tim