Python、字符串、unicode 字符
comp/INFO_MAP_ECE/101102.1.119
该字符串是CPU的输出,但数字后面总是有特殊/不可打印的字符,我的目标是获取不包括前面的文本和特殊字符的数字/ 之后不可打印。我正在尝试 split 方法,但不确定如何用于特殊/不可打印字符。有人可以建议一下吗?这将是一个很大的帮助。谢谢。
comp/INFO_MAP_ECE/101102.1.119
This string is the output of a CPU but there are always special/non-printable characters after the number and my aim is to obtain the number excluding the text before it and special/non-printable after it. I am trying the split method but am not sure what to use for special/non-printable characters. Can anyone please suggest something? It would be a great help. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的输出总是看起来像您所显示的那样,您可以使用 正则表达式
:这里的模式查找 /,然后是一些数字和句点,然后是任何内容,然后仅提取数字和句点。只要您始终获得与该描述匹配的字符串,这就应该有效。
哈!
Assuming your output always looks something like what you showed, you can use a regular expression:
The pattern here looks for a /, then some numbers and periods, then anything, and extracts just the numbers and periods. This should work as long as you're always getting a string that matches that description.
HTH!
数字的长度总是相同吗?如果是这样,你可以直接切片字符串。
Is the number always the same length? If so you could just slice the string.