Python提取字符串中的FPS数据
可以使用正则表达式来提取字符串中的数字部分。以下是一个使用正则表达式的示例代码:
import re
string = '1479FPS, OpenGL 4.0 Tessellation - GPU Caps Viewer'
pattern = r'\d+' # 匹配一个或多个数字
match = re.search(pattern, string)
if match:
fps = match.group(0)
print(fps)
else:
print('No FPS found')
这段代码使用了re.search()函数来搜索字符串中匹配正则表达式的部分。如果找到了匹配项,就使用match.group(0)来获取匹配的结果。输出结果为:
1479
原文地址: https://www.cveoy.top/t/topic/qkuI 著作权归作者所有。请勿转载和采集!