如何在java中拆分字符串 [英] how to split the string in java
本文介绍了如何在java中拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Windows中拆分java中的字符串?
我使用
例如。
how to split the string in java in Windows? I used Eg.
String directory="C:\home\public\folder";
String [] dir=direct.split("\");
我想知道如何拆分例如字符串。
在java中,如果我使用split(\)
,则会出现语法错误。
I want to know how to split the string in eg.
In java, if I use "split("\")"
, there is syntax error.
谢谢
推荐答案
split()
Java中的函数接受常规表达式。所以,你真正需要做的是两次转义反斜杠字符:
split()
function in Java accepts regular expressions. So, what you exactly need to do is to escape the backslash character twice:
String[] dir=direct.split("\\\\");
一个用于Java,一个用于正则表达式。
One for Java, and one for regular expressions.
这篇关于如何在java中拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文