mirror of
https://github.com/BinomialLLC/basis_universal.git
synced 2026-06-12 10:33:51 +00:00
13 lines
388 B
Python
13 lines
388 B
Python
# convert_to_c_string.py
|
|
def to_c_string(path):
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
text = f.read()
|
|
# escape backslashes and quotes
|
|
text = text.replace("\\", "\\\\").replace("\"", "\\\"")
|
|
# replace newlines with \n
|
|
text = text.replace("\n", "\\n\"\n\"")
|
|
return "\"" + text + "\""
|
|
|
|
if __name__ == "__main__":
|
|
print(to_c_string("cmd_help.txt"))
|