从indexof(word)到下一行的子字符串(substring from indexof(word) until next line)

编程入门 行业动态 更新时间:2024-10-23 13:27:04
从indexof(word)到下一行的子字符串(substring from indexof(word) until next line)

我想从indexof("&")直到下一行的subString,我的代码是

String substring = thisSrch.srchdesc.substring(thisSrch.srchdesc.indexOf("&"), frstNextNewLine);

但我不知道我怎么能找到frstNextNewLine为frstNextNewLine我想检测“ &Ali是加入的第一个人。 ”在下面的文字

一个美妙的宁静占据了我的整个灵魂,就像我春天的甜蜜的早晨,我全心全意地享受。

&Ali是第一个加入的人。

我独自一人,在这个地方感受到存在的魅力,这是为了像我一样的灵魂所创造的。

i want subString from indexof("&") until next line,my code is

String substring = thisSrch.srchdesc.substring(thisSrch.srchdesc.indexOf("&"), frstNextNewLine);

but i dont know how i can find frstNextNewLine for exmaple i want detect "& Ali is First person that joined." in below text

A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart.

& Ali is First person that joined.

I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine.

最满意答案

int andIndex = thisSrch.srchdesc.indexOf("&"); String substring = thisSrch.srchdesc.substring(andIndex, thisSrch.srchdesc.indexOf("\n", andIndex));

上面使用的indexOf函数接受一个参数,以开始在'&'字符的索引之后查找新行。

int andIndex = thisSrch.srchdesc.indexOf("&"); String substring = thisSrch.srchdesc.substring(andIndex, thisSrch.srchdesc.indexOf("\n", andIndex));

The indexOf function used above accepts a parameter to starting looking for new line after the index of the '&' character.

更多推荐

本文发布于:2023-07-07 21:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   word   indexof   substring   line

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!