Javascript match function problem

56 views
Skip to first unread message

Prakash Ranganthan

unread,
Dec 18, 2012, 4:58:32 AM12/18/12
to greasemon...@googlegroups.com
The following is my greasemonkey script  I have text  "ABC-2105" in my text file in a line and in the website I have "ABC-210" it is actually matching both text and getting the text value  I dont know what went wrong. Any help is much appreciated. Thanks in advance

function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}
GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://*******/newscript/Test.txt',
    ignoreCache: true,
    headers:
            {
                'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
                'Accept':'text/plain',
                },
    onload: function(responseDetails)
    {
         
         var atcid = new Array();
         atcid = responseDetails.responseText.split("\n");
         var tempo =document.getElementsByTagName('p')[6].textContent;
         var cid = tempo.split(":")
         var tc = trimAll(cid[1]);
         var tempcid = tc.split(" ")
         var datcid = tempcid[0];
         var logo = document.createElement("div");
         logo.style.color = 'red';
         var text = document.createTextNode(" None ");
         for (x in atcid)
         {
         var str = trimAll(atcid[x]);
         var ttcid = trimAll(datcid);
         var result = str.match(ttcid);
         if (result != null)
          {text.textContent = ' ' +atcid[++x];
          break;}
         else{ ++x;
          text.textContent = ' ';}
         }

Matt Sargent

unread,
Dec 20, 2012, 12:21:32 PM12/20/12
to greasemon...@googlegroups.com
Just FYI, There's been a native javascript trim() function since Firefox
3.5.
> --
> You received this message because you are subscribed to the Google
> Groups "greasemonkey-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/greasemonkey-users/-/QppNKB6MTfAJ.
> To post to this group, send email to greasemon...@googlegroups.com.
> To unsubscribe from this group, send email to
> greasemonkey-us...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/greasemonkey-users?hl=en.


Anthony Lieuallen

unread,
Dec 20, 2012, 12:40:22 PM12/20/12
to greasemon...@googlegroups.com
On Thu, Dec 20, 2012 at 12:21 PM, Matt Sargent <matt.s...@locusprime.net> wrote:
Just FYI, There's been a native javascript trim() function since Firefox 3.5.

Wow.  And it's relatively cross-browser too.
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/Trim
Reply all
Reply to author
Forward
0 new messages