Solved

JScript parsing

Posted on 2004-10-20
14
209 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with Javascript to round decimal points to 2 13 35
Use Mid in Html 6 22
Calculating percentage 2 30
AngularJS: ng-repeat 25 26
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 …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

733 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