如何将字符串分割成一半的Andr​​oid? [英] How to split a string into half in android?

查看:81
本文介绍了如何将字符串分割成一半的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,我想将它一分为二?

 字符串数据=这是一个字符串

这是一个例子字符串。在现实情况下,我不知道什么是里面的字符串,它有多长等等


解决方案

 字符串数据=这是一个字符串;
串half1 = data.subString(0,data.length()/ 2);
串half2 = data.subString(da​​ta.length()/ 2);

此外,请记住字符串是不可改变的,你不能只叫 data.subString(da​​ta.length()/ 2); 并期望数据将被改变。你必须将返回的字符串到某个变量(如在我的例子)。

I have a string i want to split it into half?

String Data = "This is a string"

This is an example string. In the real case i will not know what is inside the string, how long it is etc

解决方案

String data = "This is a string";
String half1 = data.subString(0, data.length() / 2);
String half2 = data.subString(data.length()/2);

Also, remember that Strings are immutable, you can't just call data.subString(data.length()/2); and expect that data will be changed. You have to assign the returned String to some variable (as in my example).

这篇关于如何将字符串分割成一半的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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