How to find second occurence of specified value from user input and return the values in between
Question:
Currently trying to write a script that takes a user input that has multiple numbers, a hypen, then a string of letters, another hyphen and some numbers. What I’m trying to do is display the values between the two hyphens.
Here’s what I have so far
serialNum = input("Input the serial code of the product please")
hyphenIndex = serialNum.find("-")
print("The color of the product is ", serialNum[hyphenIndex:])
Answers:
If you always have the input between hyphens, the most simple thing you can do is splitting on the hyphen and get the second value:
serialNum = "34783-red-348943"
print("The color of the product is ", serialNum.split("-")[1])
Currently trying to write a script that takes a user input that has multiple numbers, a hypen, then a string of letters, another hyphen and some numbers. What I’m trying to do is display the values between the two hyphens.
Here’s what I have so far
serialNum = input("Input the serial code of the product please")
hyphenIndex = serialNum.find("-")
print("The color of the product is ", serialNum[hyphenIndex:])
If you always have the input between hyphens, the most simple thing you can do is splitting on the hyphen and get the second value:
serialNum = "34783-red-348943"
print("The color of the product is ", serialNum.split("-")[1])