python - 我如何在 <> "hi 中获取字符串"
问题描述
如何使用python获取尖括号内的字符串。我想要“helloeveryone.c”作为输出请让我知道我是 python 新手
解决方案
Use String's find
method:
In [565]: s = "hi<helloeveryone.c>"
In [567]: s[s.find("<")+1:s.find(">")]
Out[567]: 'helloeveryone.c'
Explanation:
Slice the string
from index where you find <
to the index of >
.
EDIT:
Use split
method:
In [572]: s[s.find("<")+1:s.find(">")].split('.')[0]
Out[572]: 'helloeveryone'
推荐阅读
- flutter - 使用飞镖在颤动中遍历按钮按下列表
- java - 休眠选择仅从 sybase 数据库返回 1 行
- wordpress - WordPress 块编辑器:将标签选择器面板变成基于复选框的选择器
- c - Flex 与 C ,使未知的情况
- wkwebview - 简单 WKWebView 的 loadHTMLString 在运行时因错误 WebPageProxy::processDidTerminate: (pid 0) 而崩溃,原因 3
- python - 使用 GNUPG 在 Python 中解密 PGP 文件
- reactjs - 为什么同时使用 BrowserRouter、Switch 和自定义路由不起作用?
- java - 如何提取数组中相同字符的最大序列?
- java - Eclipse BIRT 在新 Mac 上无法正常工作
- r - 带有 ggplot2 的辅助 x 轴