Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check if a sub string is in quotes?

I have this code and I want to check if a sub string is in quotes. I’m trying to make a programming language.

code = """
Console.Print("Hello"); Console.Print("World");
"""

Any help would be appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Not sure what exactly you want to do with the output, but a brute-force approach would be looping through the string.

code = '''Console.Print("Hello"); Console.Print("World");
'''

display = False
words = []
new_word = ''
for letter in code:
    if letter == "\"" and not display:
        display = True
    elif letter == "\"":
        words.append(new_word)
        new_word = ''
        display = False
    if display and letter!='\"':
        new_word +=letter
        
print(words)

Probably not the most efficient approach.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading