Issue
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.
EDIT: I found that you can use regex to do this.
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.
Answered By - bthalpin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.