处理机器人应用程序,所以我需要从消息字符串中提取值,并将其传递给一个变量。消息字符串可以采用不同的方式,例如:
message = 'name="Raj",lastname="Paul",gender="male", age=23'
message = 'name="Raj",lastname="Paul",age=23'
message = 'name="Raj",lastname="Paul",gender="male"'
用户提供的数据可以包含所有值,或者有时会缺少年龄或性别字段。
我被卡住的地方是,I am not sure how to check if age is present in the message text. If it is then extract value corresponding to age. If age is not in message, ignore age.
可以检查循环中的每个单词并提取字符串,但它会变得相当长。如果有更简单的方法,请告诉我
喜欢
if Age is present in message then get the value of age,
if lastname is present in message then get the value of lastname
if gender is present in message then get the value of gender
if name is present in message then get the value of name
https://stackoverflow.com/questions/56065023
复制相似问题