连接两个字符串 [英] concatenate two strings

查看:172
本文介绍了连接两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有从游标得到的字符串,这种方式:

Let's say I have a string obtained from a cursor,this way:

String name = cursor.getString(numcol);

和像这样的另一个字符串:

and another String like this one:

String dest=cursor.getString(cursor.getColumnIndexOrThrow(db.KEY_DESTINATIE));

如果最后我想获得他们两个的字符串,是这样的:

If finally I wanna obtain a String from the two of them,something like:

name - dest

让说,如果名称=马尔默和dest =哥本哈根

Let say if name=Malmo and dest=Copenhagen

我怎么能最终获得马尔默 - 哥本​​哈根???

How could I finally obtain Malmo-Copenhagen???

由于Android将不会让我写:

Because android won't let me write :

name"-"dest

感谢ü!

推荐答案

在我的眼里,最好的办法是使用 CONCAT()方法,通过所提供的字符串类本身。

The best way in my eyes is to use the concat() method provided by the String class itself.

的使用率会,你的情况,是这样的:

The useage would, in your case, look like this:

String myConcatedString = cursor.getString(numcol).concat('-').
       concat(cursor.getString(cursor.getColumnIndexOrThrow(db.KEY_DESTINATIE)));

这篇关于连接两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆