You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
1 month ago
|
import os
|
||
|
# 使用示例
|
||
|
file_path = './GameCs.proto' # 替换为你的文件路径
|
||
|
out_path = './GenClassConfig'
|
||
|
def extract_message_text(file_path):
|
||
|
result = []
|
||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||
|
for line in file:
|
||
|
if 'message' in line:
|
||
|
start = line.find('message') + len('message')
|
||
|
end = line.find('{', start)
|
||
|
if end != -1:
|
||
|
extracted_text = line[start:end].strip()
|
||
|
# 去除所有空格
|
||
|
extracted_text = extracted_text.replace(" ", "")
|
||
|
result.append(extracted_text)
|
||
|
else:
|
||
|
extracted_text = line[start:].strip()
|
||
|
# 去除所有空格
|
||
|
extracted_text = extracted_text.replace(" ", "")
|
||
|
result.append(extracted_text)
|
||
|
return result
|
||
|
|
||
|
|
||
|
extracted_texts = extract_message_text(file_path)
|
||
|
|
||
|
def write_file_list(file_list, output_file):
|
||
|
with open(output_file, 'w') as f:
|
||
|
for file_name in file_list:
|
||
|
f.write(file_name + '\n')
|
||
|
|
||
|
write_file_list(extracted_texts, out_path)
|