如何获取给定字符串的子字符串,直到第一次出现指定字符? [英] How to take substring of a given string until the first appearance of specified character?
本文介绍了如何获取给定字符串的子字符串,直到第一次出现指定字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题是针对 perl 的.
The question is for perl.
例如,如果我有 "hello.world"
并且指定的字符是 '.'
那么我想要的结果是 "hello"
>.
For example if I have "hello.world"
and the specified character is '.'
then the result I want is "hello"
.
推荐答案
参见 perldoc -f index
:
$x = "hello.world";
$y = substr($x, 0, index($x, '.'));
这篇关于如何获取给定字符串的子字符串,直到第一次出现指定字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文