开发者

Take the delimiter that made Scanner to stop

开发者 https://www.devze.com 2023-03-07 20:24 出处:网络
I am using Java\'s Scanner to parse some text. Say I have set as a delimiter a variety of characters [@$]

I am using Java's Scanner to parse some text. Say I have set as a delimiter a variety of characters [@$]

With next I get the text till that delimiter, but I wou开发者_Go百科ld like for a way to learn if parsing stopped because it found @ or because it found $.

Is there some way to do that? Or should I break it in two, as in try with the first delimiter, and if you fail try with the second?


Found it! :) You can use

scanner.findWithinHorizon("[\\@]", 2)

to see if @ was the delimeter found.

0

精彩评论

暂无评论...
验证码 换一张
取 消