如何在反斜杠处拆分java字符串 [英] How to split a java string at backslash
本文介绍了如何在反斜杠处拆分java字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
String fname="C: extfilesdbqueryquery.txt";
这是我需要拆分的字符串.
this is the string i need to split it.
我试过这个
String [] items=fname.split("");
但不工作.
String [] items=fname.split("\"); also not working...
如何分割这个字符串...
how to split this string...
推荐答案
首先,您发布的问题中不能有字符串
First of all you can not have a string as you posted in question
String fname="C: extfilesdbqueryquery.txt";
这应该被替换为
String fname="C:\textfiles\db\query\query.txt";
因为反斜杠("") 也需要转义.
as backslash("") needs an escape as well.
最后你需要做这样的事情来拆分它们:
Finally you need to do something like this to split them:
String fname="C:\textfiles\db\query\query.txt";
String[] items= fname.split("\\");
System.out.println(Arrays.toString(items));
希望这会有所帮助.
这篇关于如何在反斜杠处拆分java字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文