Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 11:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Detecting Text String Blank spaces
PostPosted: October 9th, 2014, 1:01 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Moved this to this new topic from the Word Frequency Counter (http://www.digitalgrapevine.info/viewtopic.php?f=4&t=5512&start=30). Am so far not able to both detect text string blank spaces and then remove these from a string.

Have tried to use charCode which appears to return an empty string: no entry in Debug.trace. Doesn't seem to equate with ""

Also tried charCodeAt which does return 32 for a blank space. But not sure how to get/set/replace selection for this return.

Not sure how to use this return (32) in a script to remove more than one consecutive blank space. Retaining single blank spaces is necessary between words in the string, but multiple blank spaces seem to throw off the text selection when the string is used to populate the list box. After a section in the listbox of blank space (where for example there was a gap in the original text), any selection is roughly off by the amount of blank space in between.

Here's a script that was tried but doesn't work to remove the spaces.

Code:
function checkWord(w){

var tmpFound = false;

for (var b=0;b<myWordsArray.length;b++){

   if (String.toupper(myWordsArray[b].word) == String.toupper(w)) {
      myWordsArray[b].count++;
      tmpFound = true
      }
}
for (m = 0;m<commonwordarray.length;m++){
if  (String.toupper(w) == commonwordarray[m]){
tmpFound = true
}
}

for (var g=0;g<myWordsArray.length;g++){
tmpCode = myWordsArray[g].word.charCodeAt(g);
   if (tmpCode == 32) {     
tmpLetter = " ";     
tmpFound = true;
      }
}

if (!tmpFound)myWordsArray[b] = new WORDOBJECT(w);

}
function WORDOBJECT(w){
this.word = w.tolower();
this.count = 1;
}


Any suggestions appreciated.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Detecting Text String Blank spaces
PostPosted: October 9th, 2014, 1:19 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Code:
myString = myString.split("  ").join(" ")


Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Detecting Text String Blank spaces
PostPosted: October 9th, 2014, 1:55 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Mack,

Thank you for suggesting this. Been using it to try out different scripts with some success.

The following works on smaller amounts of text (a few lines) but is quite slow (and I'm testing on a core i-7 high spec computer). Sometimes crashes. Larger text (a few paragraphs) gets hung up, fails (needed task manager to end).

Code:
for (var a=0;a<myWords.length;a++){
myWords = myWords.split("  ").join(" ");
myWords = myWords.split("\n").join(" ");
}
Debug.trace(myWords);


Since the size of the text can vary, small to large, need to figure out how to use this or a variation for larger blocks of text, not have it hang up.

Maybe there is a "cleaner" way to do this without slowing, hanging up, crashes?

Any suggestions appreciated.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Detecting Text String Blank spaces
PostPosted: October 10th, 2014, 7:50 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
stephen wrote:
...but is quite slow...

Dry run it in your head.

Pick a phrase such as "The quick Red Fox"

The first thing you're doing is putting it into a FOR loop the length of the string - so TWENTY times!

EACH time you loop you're asking it to do two things - remove all double spaces and remove all new lines from the string.

Can you see problem?

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Detecting Text String Blank spaces
PostPosted: October 10th, 2014, 1:30 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Yes, Mack. Thank you.

Seems that if I simply remove the "for" loop, the replacement works quickly. :oops:

I'll test some more, but looks like problem solved.

Again, thank you.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group