jeudi 6 août 2020

Shell writing - Extracting something from a string while ignoring spaces

I am writing a simple shell-type of program, where the user can input different actions and the interpreter translates them to actions on my created variables via the use of std::string.

One of the actions the user can do is initiate a specific command on a specific variable for example:

delete(K1) // K1 is the variable

I want to build a function which recognises the variable inside the command, yet I faced a challenge since I need this function to also be able to ignore whitespaces which aren't harmful for the command. for example:

delete( K1 )

is okay, yet:

delete(K 1)

is not okay.

so there are two challenges here, identifying the variable from inside the parenthesis, and be able to ignore the needed whitespaces..

I have no clue where to begin here, since I couldn't find any methods under std::string that could help my with this. How would you go about solving this problem?

Thank you!

Aucun commentaire:

Enregistrer un commentaire