'Find String out of String with Data in Python
I need to find a String out of String from an JSON data. I do have given an Data to search for the right string. Here is what i have done so far:
description = "Range: 1 = RED_STRAWBERRYS, 2 = WHITE_STRAWBERRYS, 3 = PINK_RASPBERRY, 4 = BLUE_BERRY"
data = "4"
data_plus_one = "5"
msg = (description[description.find(str(data))+len(description[0:4]):description.rfind(", "+data_plus_one +" =")])
print(msg)
It does work. If I search for RED_STRAWBERRYS I do have the data = 1. And I get it back. But if i look for the last element. In this case for BLUE_BERRY then I get "BLUE_BERR" back without the last Letter. Does someone now a better way than this solution?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
