如何格式化从服务器收到的消息?

时间:2013-04-04 11:24:24

标签: java android

我有一个非常简单的客户端服务器应用程序。在我向服务器发送消息的那一刻,它发回一些信息,我想做的是让android(客户端)格式化它收到的消息,就像将消息的一部分放在textview / editText中一样另一半是另一半。有没有办法做到这一点?

非常感谢任何帮助,并提前致谢。

所以我将从android发送50126057行,服务器将发回“prd | 50126057 | 12bars | 5 | 199 | 1 | [)”它将此作为字符串发送。

1 个答案:

答案 0 :(得分:1)

是的!例如,您可以使用表达式(使用正则表达式)或使用substsr()来拆分String。

String response = "Hello, World";
String[] words = response.split(" ");
TextView tv1 = (TextView) findViewById(R.id....);
TextView tv2 = (TextView) findViewById(R.id....);
tv1.setText(words[0]);
tv2.setText(words[1]);