从Java中的字符串中删除第一个单词 [英] Remove first word from a string in Java
本文介绍了从Java中的字符串中删除第一个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从Java中的字符串中删除第一个单词的最佳方法是什么?
What's the best way to remove the first word from a string in Java?
如果我有
String originalString =这是一个字符串";
我要从中删除第一个单词,实际上是形成两个字符串-
I want to remove the first word from it and in effect form two strings -
removedWord = "This"
originalString = "is a string;
推荐答案
简单.
String o = "This is a string";
System.out.println(Arrays.toString(o.split(" ", 2)));
输出:
[This, is a string]
在下面的第2行中,值存储在 arr
数组中.像普通数组一样访问它们.
In line 2 below the values are stored in the arr
array. Access them like normal arrays.
String o = "This is a string";
String [] arr = o.split(" ", 2);
arr[0] // This
arr[1] // is a string
这篇关于从Java中的字符串中删除第一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文