E
E
ellz2018-12-09 16:34:45
Regular Expressions
ellz, 2018-12-09 16:34:45

How to extract data from a string?

Hello. The line looks like this:
{" level " : 1 , " moves " : 15}, {" level " : 2 , " moves " : 28}, {" level " : 3 , " moves " : 25
} moves. For example, I pass "2" to the method, it returns "28". How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2018-12-09
@ellz

  1. Wrap the string in square brackets [ ] on both sides and then you can interpret the final string as JSON:
  2. Using JSON parsing tools, get an array of objects,
  3. in which (using LINQ) find the object that has the desired level, and take the value of its moves

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question