Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何从split()方法获取拆分的字符串_Regex_String_Split - Fatal编程技术网

Regex 如何从split()方法获取拆分的字符串

Regex 如何从split()方法获取拆分的字符串,regex,string,split,Regex,String,Split,嗨,朋友们,我正在尝试从用户在我的jsp表单中输入的全名中获取分开的名字和姓氏。在提交表单时收到全名后,我将全名拆分为两个字符串,并用空格分隔符分隔。这是解释我的问题的代码。请帮忙 String name = request.getParameter("name"); String userType = request.getParameter("usertype"); //split the name into first_

嗨,朋友们,我正在尝试从用户在我的jsp表单中输入的全名中获取分开的名字和姓氏。在提交表单时收到全名后,我将全名拆分为两个字符串,并用空格分隔符分隔。这是解释我的问题的代码。请帮忙

           String name = request.getParameter("name");
            String userType = request.getParameter("usertype");
            //split the name into first_name and last_name
            String  splittedName[] = StringUtils.split(name);

            System.out.println(Arrays.toString(splittedName));

            String firstname = splittedName[0];
            String surname = splittedName[1];
在调试应用程序时,在所有行上设置断点。尝试将splittedName[0]和splittedName[1]值转换为“firstname”和“姓氏”字符串时出错。请帮忙…对不起,我的问题中有任何愚蠢的错误

   String name = "Kamlesh Sharma";

    String splittedName[] = name.split(" ");
    System.out.println(Arrays.toString(splittedName));

    String firstName = splittedName[0];
    String lastName = splittedName[1];
这将符合你的目的

注意:
您需要在split方法中提供分隔符,而不是要传递的名称

发布错误报告。变量
name
的值是多少?使用
StringUtils.split(name)
在下面的示例中起作用。使用调试器检查name的内容。