如何用一些模式匹配替换字符串

编程入门 行业动态 更新时间:2024-10-12 08:23:50
本文介绍了如何用一些模式匹配替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨 任何人都可以帮助我在c# 中使用正则表达式来获得解决方案基本上我必须在 * p0x0Y 之前添加一些文字模式。在这个模式中,p,x,y将是固定值,0可以被任何数字替换。 i必须编辑

string str = ?? l8c1E? * p0x0Y

在此字符串中* p0x0Y可以是* p1x1Y或* p2x2Y。 和编辑后的输出应该是* p0x0Y格式

string output = 18c1EXXX * p0x0Y

提前致谢。

解决方案

尝试:

string str = l8c1E * p0x0Y; string output = Regex.Replace(str, @ (\ * p\dx \ dY), @ XXX

1);

嗨OriginalGriff,你的解决方案对我有用,现在我想再问一件事......我必须在下面的文字中将左侧字符串替换为右侧字符串..在本文中左箭头标志是一个符号我无法复制粘贴,所以我用文字写了它,它只是一个符号。所以请给我正则表达式代码来替换它。左箭头标志* p0x0Y - >左箭头标志xxx左箭头标志 * p0x0Y我清楚我的要求,原件? 如果不知道确切的字符,我不能确定,但是...点字符匹配任何东西,所以它可能是你想要的是:

string output = Regex.Replace(str, @ (。)(\ * p\dx \ dY), @

1XXX

Hi Can anybody help me to get the solution using regular expression in c# basically i have to add some text before *p0x0Y pattern . In this pattern p,x,y will be fix value and 0 can be replace by any number . i have to edit a

string str= "l8c1E*p0x0Y"

In this string *p0x0Y can be *p1x1Y or *p2x2Y . and after editing output should be according *p0x0Y format

string output = "18c1EXXX*p0x0Y"

Thanks in advance .

解决方案

Try:

string str = "l8c1E*p0x0Y"; string output = Regex.Replace(str, @"(\*p\dx\dY)", @"XXX

1");

"Hi OriginalGriff , Your solution worked for me , now i want to ask one more thing ... i have to replace left side string into right side string in below text .. In this text "left arrow sign" is one symbol which i could not copy paste so i wrote it in text ,its just one symbol. So please give me regular expression code to replace it . "left arrow sign"*p0x0Y --> "left arrow sign"xxx "left arrow sign"*p0x0Y Am i clear about my requirement , Original ?" Without knowing the exact character, I can't be sure, but...the dot character matches anything, so it might be that what you want is:

string output = Regex.Replace(str, @"(.)(\*p\dx\dY)", @"

1XXX

更多推荐

如何用一些模式匹配替换字符串

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

发布评论

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

>www.elefans.com

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