The question is for perl.
For example if I have "hello.world"
and the specified character is '.'
then the result I want is "hello"
.
Use the substring() method to get the substring before a specific character, e.g. const before = str. substring(0, str. indexOf('_')); . The substring method will return a new string containing the part of the string before the specified character.
To get the substring after a specific character, call the substring() method, passing it the index after the character's index as a parameter. The substring method will return the part of the string after the specified character.
Use the split() method to cut string before the character in Python. The split() method splits a string into a list. After listing into the list take only 0 indexed values.
See perldoc -f index
:
$x = "hello.world";
$y = substr($x, 0, index($x, '.'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With