eclipse - 从 html 文件中提取 £(英镑)货币符号和金额 (56)
问题描述
从 html 文件中提取£
(英镑)货币符号和金额(56)。它将金额打印为£56
并将货币打印为Â
。我怎样才能只打印 56,没有符号?它与$
标志一起工作正常。
部分代码:
cost= "£56"
currencySymbol = cost[0]
print (currencySymbol, cost[1:])
我得到的输出:
Â: £56
解决方案
有很多方法可以做到这一点,你可以使用split,regex和我在下面做的一种方法:希望它可以帮助你
import re
cost= "£560,000"
match = re.search(r'([\D]+)([\d,]+)', cost)
output = (match.group(1), match.group(2).replace(',',''))
print (output);
output -->('£', '560000')
在这里检查(https://ideone.com/Y053Vb)
推荐阅读
- javascript - 使功能启用/禁用组合框 ExtJS
- tabulator - 尝试创建可下载的制表符表,但未显示按钮
- mysql - 如何在不使用 Django 模型的情况下使用 MySQL 中的完整数据库
- javascript - WebGL:使用 tf.browser.fromPixels 转换本地图像时出现 INVALID_VALUE
- jquery - 如何在不刷新页面的情况下自动将新插入的mysql数据显示到laravel视图中?
- vhdl - 与其他 if-else 语句具有相同条件的 if-else 语句不会产生相同的输出
- kubernetes - 主动/被动路由具有多个后端的无头服务
- python-3.x - 使用记事本打开文件时出现 Python3 _io.TextIOWrapper 错误
- rundeck - Rundeck GA 版本兼容性
- image - 在 React Native 中有条件地渲染图像