我有一个从我的数据库中查询的项目列表。此列表在每个项目中有两个单词,这两个单词由空格分隔。我现在想要只访问空格后面的最后一个单词。
来自我的数据库的查询
public List<String> getList(){
List<String> array = new ArrayList<String>();
String selectQuery = "SELECT * FROM " + TABLE_LIST;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
ArrayList<ArrayList<String>> row = new ArrayList<ArrayList<String>>();
if (cursor .moveToFirst()) {
;
do {
String listName = cursor.getString(cursor.getColumnIndex(ITEM_A));
array.add(listName);
}while(cursor.moveToNext());
}
cursor.close();
return array;
}
访问查询中的项目
List<String> m = new ArrayList<String>();
m = dbHelper.getList();
System.out.println(m);
这给出了以下输出
[itemOA AITEME,itemOD BITEMD,itemOC CITEMS, itemOB DTEM]
但我希望得到列表的最后一句话,
[AITEME, BITEMD, CITEMS ,DTEM]
感谢您的帮助。
答案 0 :(得分:1)
我认为您可以重新构建代码以避免必须执行此操作,但是:
class GameScene: SKScene {
var foreground: SKNode!
var hud: SKNode!
var firstBall: SKNode!
var scoreLabel: SKLabelNode!
private var score = 0
override func didMoveToView(view: SKView) {
scoreLabel = SKLabelNode(fontNamed:"Geared-Slab")
scoreLabel.fontColor = UIColor.blackColor()
scoreLabel.position = CGPoint( x: self.frame.midX, y: 3 * self.frame.size.height / 4 )
scoreLabel.fontSize = 100.0
scoreLabel.zPosition = 100
scoreLabel.text = String(score)
self.addChild(scoreLabel)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if(firstBall.containsPoint(location)) {
firstBall.physicsBody?.velocity = CGVectorMake(0, 600)
firstBall.physicsBody?.applyImpulse(CGVectorMake(0, 1100))
}
if
let touch : UITouch! = touches.first,
let tappedSprite = nodeAtPoint(touch!.locationInNode(self)) as? SKSpriteNode,
let scoreLabel = childNodeWithName("scoreLabel") as? SKLabelNode
where tappedSprite.name == "ballPoints" {
score += 1
scoreLabel.text = "Score: \(score)"
}
}
}
override init(size:CGSize) {
super.init(size: size)
foreground = SKNode()
addChild(foreground)
//1st Ball//
firstBall = createPlayer()
foreground.addChild(firstBall)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
只要你总是有一个已知的起点(如果它始终以“itemOA”或6个字符+一个空格开头)就会工作