I need to find string in the text and truncate text untill this string
Elzbieta
Registered Posts: 1 ✭
Operating system used: windows
Operating system used: windows
Tagged:
Answers
-
Here's a Python function that truncates a string until a certain key and returns only the part to the right of the key:
def truncate_string(input_string, key):
# Find the position of the key in the input string
key_position = input_string.find(key)
# If the key is found, return the substring starting from the right of the key
if key_position != -1:
return input_string[key_position + len(key):]
else:
return input_string
# Example usage
input_string = "someone@gmail.com"
key = "@"
result = truncate_string(input_string, key)
print(result) # Output: gmail.comThis function searches for the key in the input string and returns the substring that follows the key. If the key is not found, it returns the original string. In the example provided, it correctly returns gmail.com
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,188 Neuron