使用分隔符将Java字符串拆分为两个字符串 [英] Split Java String into Two String using delimiter

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

问题描述

我有一个字符串,其值为 name:score 。我想将字符串拆分为两个字符串,字符串 a ,其值为 name 和字符串 b ,其值为得分

I have a string that has the value of name:score. I want to split the string into two strings, string a with the value of name and string b with the value of score.

正确的函数/语法是什么这样做?

What is the correct function/syntax to do this?

我看了 string.split ,但找不到实际的语法来返回数据分成两个单独的字符串

I have looked at string.split, but can not find the actual syntax to return the data into two separate strings.

推荐答案

拆分功能适用于:

String[] str_array = "name:score".split(":");
String stringa = str_array[0]; 
String stringb = str_array[1];

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

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