在java中如何从字符串中获取子字符串直到字符c? [英] In java how to get substring from a string till a character c?

查看:100
本文介绍了在java中如何从字符串中获取子字符串直到字符c?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串(基本上是命名约定后的文件名) abc.def.ghi

I have a string (which is basically a file name following a naming convention) abc.def.ghi

我想在第一个之前提取子字符串。(即一个点)

I would like to extract the substring before the first . (ie a dot)

在java doc api中,我似乎无法在String中找到这样做的方法。

我错过了什么?怎么做?

In java doc api, I can't seem to find a method in String which does that.
Am I missing something? How to do it?

推荐答案

查看 String.indexOf String.substring

确保为 indexOf 检查-1。

这篇关于在java中如何从字符串中获取子字符串直到字符c?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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