使用正则表达式的字符串操作

编程入门 行业动态 更新时间:2024-10-27 23:25:04
本文介绍了使用正则表达式的字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

很抱歉昨天的问题. 有一个名为"something.docx"的字符串.如何使用正则表达式拆分字符串. 还可以找到如何修改".docx"扩展名,即如何用".pdf"替换它. 如何查找字符串的反义,意味着在"something.docx"中,您可能会从头开始,找到第一个.(点),然后将字符串拆分成那个.(dot),并捕获前面的字符串,意味着"something"并添加".pdf"扩展名. 注意:您将"something.docx"视为字符串,而不是文档,并且也不会转换为pdf格式.只需将.docx替换为.pdf

sry for yesterday''s question.. There is a string named as "something.docx". How to split that string using Regular Expression. Also find how modify the ".docx" extension,means how it can be replace with ".pdf". How to find the reverse of string, means In "something.docx", you may come from back onwards, and find the first .(dot) and split the string upto that .(dot) and capture the front string means "something" and add ".pdf" extensions. Note: You consider "something.docx" as a string, not a document and also its not converted into pdf format. just replace .docx with .pdf

推荐答案

本文 [ ^ ]可以让您简要了解功能强大的正则表达式以及如何使用它们拆分字符串. This article[^] would give you a brief idea of how powerful regular expressions can be and how they could be used to split strings.

您在这里不需要正则表达式. 查看类System.IO.Path. System.IO.Path.ChangeExtension和System.IO.Path.GetExtension,System.IO.Path.GetFileName和System.IO.Path.GetFileNameWithoutExtension怎么样?它将满足您的所有需求.参见: msdn.microsoft/en-us/library/system.io. path.aspx [^ ]. 毕竟,您有string.Split. 最后的提示:没有操纵"字符串-它们是不可变的.所有方法仅读取字符串数据并从头开始创建其他数据.实际上,出于性能和其他原因,这是一个很好的了解.
—SA
You don''t need Regular expressions here. Look at the class System.IO.Path. How about System.IO.Path.ChangeExtension and System.IO.Path.GetExtension, System.IO.Path.GetFileName and System.IO.Path.GetFileNameWithoutExtension? It will cover all you need. See: msdn.microsoft/en-us/library/system.io.path.aspx[^]. After all, you have string.Split. A final note: nothing "manipulates" strings — they are immutable. All methods only read string data and created other data from scratch. Practically, this is good to know, for performance and other reasons.
—SA

更多推荐

使用正则表达式的字符串操作

本文发布于:2023-10-09 02:10:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474409.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   操作   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!