Skip to main content
Byron Nash - INSP
Inspiring
July 25, 2022
Answered

Splitting pasted text in prompt box or UI edittext

  • July 25, 2022
  • 3 replies
  • 304 views

I'm trying to allow the user to paste in some lines from Excel into a Prompt() or EditText UI element. Then split it up by the tabs to generate an array of the data pasted. This method of dealing with text data works fine when I'm reading from a text file on disk. However when I try to replicate with pasted data it fails. When I paste the data into a text editor the tabs are intact but the split() function does not seem to recognize them. Here is a piece of text code. 

var inText = prompt("Paste the text", "paste here");
alert(inText);
var broken =  inText.split("    ");
alert(broken[2]);
 
This topic has been closed for replies.
Correct answer Dan Ebberts

Try this:

var tabChar = String.fromCharCode(9);
var inText = prompt("Paste the text", "paste here");
alert(inText);
var splitText =  inText.split(tabChar);
alert(splitText.length);

3 replies

Byron Nash - INSP
Inspiring
July 25, 2022

Thanks guys. Both solutions worked. 

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
July 25, 2022

Try this:

var tabChar = String.fromCharCode(9);
var inText = prompt("Paste the text", "paste here");
alert(inText);
var splitText =  inText.split(tabChar);
alert(splitText.length);
Mylenium
Legend
July 25, 2022

Perhaps you need to designate the tab with its \t escape character or insert some regex.

 

Mylenium