parsing a line of text to get a specific number

前端 未结 3 1315
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 00:03

I have a line of text in the form \" some spaces variable = 7 = \'0x07\' some more data\"

I want to parse it and get the number 7 from \

3条回答
  •  温柔的废话
    2021-01-26 01:04

    Use a regular expression.

    Essentially, you create an expression that goes something like "variable = (\d+)", do a match, and then take the first group, which will give you the string 7. You can then convert it to an int.

    Read the tutorial in the link above.

提交回复
热议问题