W
W
wio332021-12-10 17:16:00
C++ / C#
wio33, 2021-12-10 17:16:00

How to select a substring with a fixed point number?

How to select a substring with a fixed point number?
I have a lab on the basics of programming, we go through the strings.
The data type is string and not char arrays.
It is necessary from the entered string of the following format: "ajwk123. + -ekekw.r567.12jrkel.68+-"
Get 567.12 (in this case) No ideas
how to do this at all
Please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2021-12-10
@wio33

In string, you can also refer to a single character using the indexing operator.
It's simple: In the loop, you go through the line looking for "+" or "-" or "." or any number.
If you find something from this list, then you set the strtod function on the string, starting from this position - it will convert the string to double and return the position of the first non-numeric character in the string. Print the number received from strtod to the screen. You continue the search further, starting from the position returned by strtod and so on until the end of the searched string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question