c#string [] args没有正确读取包含空格的短语从vbscript传递

时间:2014-01-25 12:23:29

标签: c# vbscript space args

我有一个使用jsp和struts构建的Web应用程序,它可以通过使用C#构建的可执行文件(.exe)与设备集成

下面是我在jsp网页上的vbscript代码

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

及以下是c#sharp mainForm中的代码,它将String [] arg作为参数

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

    InitializeComponent();

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

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

问题是当vbscript函数是触发/调用时,我传递了包含空格的值,我把MsgBox确保短语正确传递包括空格,并且它工作正常,起初我我原来的代码认为有问题

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

是从Web浏览器中输入的文件检索值,也许我没有正确结束String文字,所以我硬编码值,但是当涉及到c#sharp程序时,String [] args只显示'John'当显示消息框而未显示空格后的其余单词时。

希望有人能帮我解决问题

感谢和问候

1 个答案:

答案 0 :(得分:0)

此部分items = items & "" &表示您附加空字符串的项目是无用的。所以我想你想用双引号来附加它,以使带有空格的字符串作为一个参数处理。你可以试试这个:

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

请注意,doubling the quotes是在VBScript

中转义引号字符的方法