我有一个存储
的数组Array[0] = "Information of student, Class Allocated: 2B (13), Class Opposite: 1B (12)"
Array[1] = "Information of student, Class Allocated: 1B (12), Class Opposite: 2B (13)"
Array[2] = "Information of student, Class Allocated: 1A (10), Class Opposite: 2A (11)"
我需要 Class Allocated :和 Class Opposite 的信息。因此我需要获得2B和13,但存储在不同的变量中。哪个可以
For Array[0]
Floor = 2B
ClassNo = 13
Opposite = 1B
OppositeClass = 12
谁能告诉我如何获得它?非常感谢帮助。
答案 0 :(得分:0)
在String中使用split方法。
假设您有标准格式。
String [] commasplit = Array[0].split(",");
然后
String [] allocated = commasplit[1].split(" : ");
String allocatedValue = allocated[1] //2B (13)
根据代码,使用方法参数编写一个通用方法,这样你就不会多次写入它。