?
Solved

JScript parsing

Posted on 2004-10-20
14
Medium Priority
?
212 Views
Last Modified: 2008-02-01
You can run this script with Windows Scripting Host by invoking
cscript.exe from the Windows command shell, or by using wscript.exe
from Windows Explorer.

var emailaddr = null;
var subject = null;
var objArgs = WScript.Arguments;
if(objArgs.length >= 1) {
    emailaddr = objArgs(0);
    if(emailaddr.substr(0, 7) == "mailto:")
        emailaddr = emailaddr.substr(7);
}

cscript.exe mailto:test@foobar.com causes emailaddr = test@foobar.com.

I would to modify the above to have cscript.exe malito:test@foobar.com?Subject=help to cause emailaddr = test@foobar.com and then subject=help

THANKS!
0
Comment
Question by:rw263
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 30

Expert Comment

by:third
ID: 12365315
try,

  var emailaddr = null;
  var subject = null;
  var objArgs = WScript.Arguments;
  if(objArgs.length >= 1) {
    var strArr = objArgs[0].split('?');
    emailaddr = strArr[0];    
    if(emailaddr.substr(0, 7) == "mailto:")
        emailaddr = emailaddr.substr(7);
    subject = strArr[1].split('=')[1];
  }
0
 

Author Comment

by:rw263
ID: 12365392
objArgs.0 is null or not an object
0
 
LVL 30

Expert Comment

by:third
ID: 12365454
how about,

var strArr = objArgs(0).split('?');

replacing [] with ()
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:rw263
ID: 12365702
mailto: strArr.1 is null or not an object
mailto:test@foo.com?subject=test => works
mailto:test@foo.com => strArr.1 is null or not an object
0
 
LVL 30

Expert Comment

by:third
ID: 12365762
ok here,

if(strArr.length >= 2){
  subject = strArr[1].split('=')[1];
}
0
 

Author Comment

by:rw263
ID: 12365835
Almost there!!

mailto: -=> works
mailto:test@foo.com -=> works
mailto:test@foo.com?subject=test -=> works
mailto:test@foo.com?abc=test -=> causes emailaddr = test@foo.com, subect = test, here the email is correct, there is no subject specified though....
0
 
LVL 30

Expert Comment

by:third
ID: 12365907

ok,

if((strArr.length >= 2)&&()){
  subject = strArr[1].split('=')[1];
}


var emailaddr = null;
  var subject = null;
  var objArgs = WScript.Arguments;
  if(objArgs.length >= 1) {
    var strArr = objArgs(0).split('?');
    emailaddr = strArr[0];    
    if(emailaddr.substr(0, 7) == "mailto:")
        emailaddr = emailaddr.substr(7);
    if(strArr.length >= 2){
      var subjectArr = strArr[1].split('=');
      if(subjectArr[0]=='subject'){
        subject = subjectArr[1];
      }
    }
   
   
  }
0
 
LVL 30

Expert Comment

by:third
ID: 12365920
opps ignore the first three lines. that should not be there, my bad.

var emailaddr = null;
  var subject = null;
  var objArgs = WScript.Arguments;
  if(objArgs.length >= 1) {
    var strArr = objArgs(0).split('?');
    emailaddr = strArr[0];    
    if(emailaddr.substr(0, 7) == "mailto:")
        emailaddr = emailaddr.substr(7);
    if(strArr.length >= 2){
      var subjectArr = strArr[1].split('=');
      if(subjectArr[0]=='subject'){
        subject = subjectArr[1];
      }
    }  
  }
0
 
LVL 30

Expert Comment

by:third
ID: 12365948
better change this

if(subjectArr[0]=='subject')

to

if(subjectArr[0].toLowerCase()=='subject')
0
 

Author Comment

by:rw263
ID: 12366012
mailto: -=> works
mailto:test@foo.com -=> works, but subject comes up as null, should be blank
mailto:test@foo.com?subject=test -=> works
mailto:test@foo.com?abc=test -=> causes emailaddr = test@foo.com, subect = null, should come up as blank
mailto:test@foo.com?Subject=test -=> subject is blank (should be case insensative on SubJect

so close... thanks!!!!
0
 
LVL 30

Accepted Solution

by:
third earned 2000 total points
ID: 12366049
you can initialize it to ''

var emailaddr = '';
var subject = '';

for the case sensitivity issue, i provided the answer above.
0
 

Author Comment

by:rw263
ID: 12366070
yahoo!!!

Don't understand all the code, but it works great! THANKS!!
0
 

Author Comment

by:rw263
ID: 12366079
var emailaddr = "";
var subject = "";
var objArgs = WScript.Arguments;

if(objArgs.length >= 1) {
  var strArr = objArgs(0).split('?');
  emailaddr = strArr[0];
  if(emailaddr.substr(0, 7) == "mailto:") {
    emailaddr = emailaddr.substr(7);
    if (strArr.length >= 2) {
      var subjectArr = strArr[1].split('=');
      if (subjectArr[0].toLowerCase() == 'subject')
        subject = subjectArr[1];
    }
  }
}
0
 
LVL 30

Expert Comment

by:third
ID: 12366129
welcome.

;-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question