How can I use string split to assign multiple variables in for each loop?

Hi all, this is my first post. My project is for web navigation/scraping and I need some help.

I have an HTML form that asks for “Client SSN, Account Number, and Destination”, using Custom Input activity.

The output is stored in one variable in the HTML file.
window.external.setResult(SSN + "|" + Account + "|" + Destination);

I am using the Assign activity to break out the values separated by the | char.

Value_SSN = SearchValues.Split(CChar("|"))

Next, I want to save those split values into their own respective variables.

Can anyone offer guidance on how to complete this?

Thank you!

HTML form

<!DOCTYPE html>
<html lang="en">


    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />


          Client SSN:<br>
          <input type="text" id="SSN"><br>
          Account Number:<br>
          <input type="text" id="Account"><br>
          <input type="text" id="Destination"><br>

          <button onclick="SubmitValues()">Submit</button>

          <script type="text/javascript">
          function SubmitValues(){
            var SSN = document.getElementById("SSN").value;
            var Account = document.getElementById("Account").value;
            var Destination = document.getElementById("Destination").value;
            window.external.setResult(SSN + "|" + Account + "|" + Destination);
            return true;

Is there a real need to loop through the array just because you have split it?

Can’t you use Multiple Assign and then do:

Value_SSN= Array_Split(0)
Value_Account= Array_Split(1)
Value_Destination= Array_Split(2)

Process your variables as required

End Try

End Catch

Obviously, this assumes that there is a pattern and your string is predictable

give a try on return the string as serialized JSON like
{“SSN”:“123”, “Account”:“12345”,“Destination”:“ABC”}
but quote/unescape the "

then you can easy bring it into a dictionary by:

JsonConvert.DeserializeObject(Of Dictionary(Of String, String))(YourStringVar)

And allows you to use the key like
yourDictVar(“Account”) e.g. getting the Account

I like your suggestion but don’t know how to implement it. Also how did you get the immediate window?

Have a check on the screenshot
set a breakpoint somewhere and start debugging, once you will fet paused you can see the immediate panel

Also refer to UIPath Academy Debugging course to get trained on this as well

AndyMenon! I figured it out! Thanks!

You’re welcome Alexander! Great that you have a solution! :slight_smile: :+1:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.