版本scala 2.10。+
我有一个地址
420 Bedok North aveneu 2
我需要的只是提取
420
超出给定的行。如何获得它?
答案 0 :(得分:5)
val address = "420 Bedok North aveneu 2"
address.takeWhile(_ != ' ')
答案 1 :(得分:2)
val address = "420 Bedok North aveneu 2"
address.split(" ").head
答案 2 :(得分:-1)
var str = '420 Bedok North aveneu 2';
var newStr = '';
for (var i = 0; i < str.length; i ++) {
if (str.substring(i, i+1) == ' ') {
break;
} else {
newStr += str.substring(i, i+1);
}
}