James534 Posted June 12, 2020 Report Share Posted June 12, 2020 I am trying to figure out how to take text saved from the clipboard to a variable, and then process that text. I was able to get the first part clipboard to variable , what I am stuck on is trying to separate the text. What I would like to do , if possible is take text form the the clip board ie. one two three four (the length of the clipboard text may vary from one time to the next) convert it to: x(1) = one x(2) = two x(3) = three then to use x(1) in a different part of the code. Any help or pointing in the right direction would help Thanks James Quote Link to comment Share on other sites More sharing options...
acantor Posted June 12, 2020 Report Share Posted June 12, 2020 Hi James, One way to accomplish this is with the Split String instruction: Variable Set String %x% to "one two three" Split String "%x%" on " " into %y%, starting at 1 Text Box Display: %y[1]% Text Box Display: %y[2]% Text Box Display: %y[3]% When run, the script displays "one" then "two" then "three". When defining variable %y% I created it as an array with up to 100 elements. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 12, 2020 Report Share Posted June 12, 2020 I would do the same as acantor but I would add code to ensure it doesn't crash if there are more strings than elements of the array. Two methods come to mind. Count the number of elements in the string. To do this create a temporary variable as a copy of your clipboard string. Then remove the spaces. (Assuming there are no double spaces) then subtract it's length from the length of the original variable and add one. The other way is to use the error handler. Actually this should always be done for operations where a user could give you lord-knows-what. In the "on error" tab you will see 0x001E is the "Array is to Small". Use Catch Error commands to handle it. Help section is titled "Catch Error / End Catch Error" if you don't know how to do that yet. If those are problematic you can also chew through the string. What I have done in the past is to search for a string, often an element label in HTML but in your case it would be a space. Search for the position of that text. Grab the text up to that text (substring), evaluate it if need be, then delete that substring and repeat. Sometimes this iterative, ablative approach is quicker and less problematic. The exit of yoru loop can be condition met or when the position of the search result indicates no match. It's a safe way to process test without the overhead of error handling. Quote Link to comment Share on other sites More sharing options...
James534 Posted June 12, 2020 Author Report Share Posted June 12, 2020 Thank you for the reply Alan and Cory, will give it a try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.