我正在将请求发送到已联机的服务器-收到答案后,我将其另存为字符串。

现在的事情是,当我将代码作为本地主机测试时,一切都很好。
因此,假设某个用户注册并运行正常,然后服务器重新运行了图1。

但是当我将其放到网上时,我得到了下一个字符串-

1<!-- www.serversfree.com Analytics Code --><script src="http://www.serversfree.com"></script><noscript><a title="Free hosting servers" href="http://www.serversfree.com">Free servers</a><a title="Free websites hosting server" href="http://www.serversfree.com">Free websites hosting server</a><a title="Free hosting server features" href="http://www.serversfree.com/server-features/">Free server features</a><a title="Free hosting" href="http://www.bugs3.com">Free hosting</a><a title="Page rank" href="http://www.1pagerank.com">Page rank</a></noscript><script type="text/javascript">  var _gaq = _gaq || [];  _gaq.push(['_setAccount', 'UA-24425628-3']);  _gaq.push(['_setDomainName', window.location.host]);  _gaq.push(['_setAllowLinker', true]);  _gaq.push(['_trackPageview']);  (function() {    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);  })();</script><script type="text/javascript" src="http://www.bugs3.com/ganalytics.js"></script><!-- End Of Analytics Code -->


我只想知道返回答案的开头是什么数字-我在这里输入的代码中的数字是1。

所以我的问题是,我怎样才能“削减”剩下的答案字符串而只留下1?
当然,我更愿意在我得到答案之后在Android代码中进行剪切。

谢谢你的帮助

最佳答案

如果您想要一个字符串,可以使用:

res = res.substring(0,1);


但是,如果您想要一个字符,可以使用:

char character = res.charAt(0);

关于java - 如何获取字符串的第一个字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22250333/

10-11 22:39
查看更多