String to String Array Android项目 [英] String to String Array Android project
本文介绍了String to String Array Android项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在开发Android项目时,我已经堆积了位置
我不想描述,因为它很简单。
I don't want to describe because it is simple.
String str = "Physics,Chemistry,Biology"
这是我的 字符串 ,三个查询除以逗号。
我的一个方法返回这样的字符串。
This is my String and three queries are divided by comma. One of my method returns string like this.
所以我想把它变成一个字符串数组。
这就像基于逗号的划分。
So I want to make it to a string array. This will like that dividing comma based.
String[] strArr = {"Physics", "Chemistry", "Biology"};
推荐答案
String类中有一个方法可以帮到你转换它,
但你应该给这个方法正则表达式,在你的情况下正则表达式是,
there is a method in String class that can help you convert it,
but you should give this method the regex , in your case regex is ","
你可以使用这个方法来转换它:
you can use this method to convert it:
public String[] convertToArray(String str, String regex){
return str.split(regex);
}
String[] str = convertToArray(str, ",");
这篇关于String to String Array Android项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文