I've a web application that build using jsp and struts which is can integrate with device through executable file (.exe) that build with C#

below is my vbscript code in from jsp web page

sub launchApp()
    Dim appShell
    Set appShell = CreateObject("WScript.Shell")
    Set WshUserEnv=appShell.Environment("System")
    Dim applicantName,applicantsAddress

    applicantName=document.getElementById("applicantName").value
    applicantsAddress=document.getElementById("applicantsAddress").value

    Dim items

    /*
        this is original code which is get value from input field in web browser             
    */
    'items = items & "" & applicantName & "" & "@#"
    'items = items & "" & applicantsAddress & "" & "@#"
    /*end original code*/

    /*hard coded*/
    items = items & "John Doe" & "@#"
    items = items & "1st Avenue, LA" & "@#"
    /*end hard coded*/

    MsgBox items

    'Waited for you to close the window before it continued.
    appShell.Run WshUserEnv("applicationPath") & "\\application.exe " & items,1,True

    Set appShell = Nothing
end sub

and below is the code in c# sharp mainForm that takes String[] arg as argument

public string items = string.Empty;
public MainForm(string[] args)
{

    InitializeComponent();

    if (args.Length != 0)
    {
        items = args[0];

        MessageBox.Show(items);
    }
    else
    {
        //do another logic
    }
}

the problem is when the vbscript function are trigger/call, I pass the value which is contains space in the phrase, I put the MsgBox to ensure the phrase are pass correctly including space, and it's is working fine, At first I thought there something wrong with my original code

/*
            this is original code which is get value from input field in web browser             
        */
        'items = items & "" & applicantName & "" & "@#"
        'items = items & "" & applicantsAddress & "" & "@#"
        /*end original code*/

which is retrieve value from input filed in web browser, maybe I'm not properly end the String literal, so I hard code the value but when it comes to c# sharp program, the String[] args only display 'John' when the messagebox were shown while the rest of word after space is not appear.

hope somebody can assist me to solve the problems

thanks and regards

有帮助吗?

解决方案

This part items = items & "" & means you append items with empty string which is useless. So I guess you want to append it with double-quotes instead to make the string with space treated as one parameter. You can try this instead :

items = items & """" & applicantName & """" & "@#"
items = items & """" & applicantsAddress & """" & "@#"

Notice that doubling the quotes is the way to escape quotes character in VBScript

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top