Python:
def findRelatedValue(_string, _identifier, _maxValue):
"""
Returns a searched value (integer)
after a given identifier (string)
if it´s not greater then the given
maxValue (integer) from a given
string (string).
"""
_value = 0 # return value
_startPositionValue = 0 # position in the string where the value starts
_endPositionValue = 0 # position in the string where the value ends
_i = 0 # temporary counter
# check arguments
if not isinstance(_string, str): return 0 # check if _string is a string
if not isinstance(_identifier, str): return 0 # check if _string is a string
if not isinstance(_maxValue, int): return 0 # check if _maxValue is a integer
if len(_string) <= 0: return 0 # check if _string is not empty
if len(_identifier) <= 0: return 0 # check if _identifier is not empty
if _maxValue <= 0: return 0 # check if _maxValue is not lower then 1
# find start point
if _identifier in _string:
_startPositionValue = _string.index(_identifier) + len(_identifier)
if _startPositionValue >= len(_string): return 0 # implausible value -> error
# find end point
for _i in range(_startPositionValue, len(_string)):
if not _string[_i].isnumeric():
_endPositionValue = _i
break
# seperate value from string
if len(_string[_startPositionValue:_endPositionValue]) > 0:
_value = int(_string[_startPositionValue:_endPositionValue])
else:
return 0
if _value > _maxValue: return 0 # implausible value -> error
return _value
JS:
console.log("Hello World")