[英]how do I replace part of text in textbox in c#
我在单词自动化中使用c#时遇到问题。 我的问题是我想替换文本框中的部分文本,例如: “ ABC 12345”并用“ 123”替换12345,结果是“ ABC 123”,但是我不知道如何在文本框中获取部分文本, 我用
object firstshape = 1;
string text = w_Doc.shapes.get_Item(ref firstshape).TextFrame.TextRange.Text;
获取文本框中的原始文本,但我不知道如何获取零件文本的范围。 有什么解决方案可以在文本框中获取任意范围的文本? 提前非常感谢!!!
您可以像这样使用replace
string Replace = "12345";
string ReplaceWith = "123"
text = text.Replace("12345","123")
要获取最后5个字符,请使用以下命令:
string text = w_Doc.shapes.get_Item(ref firstshape).TextFrame.TextRange.Text;
text = text.Substring(text.Length - 5, 5);
text = text.Replace(text, "123"); //to replace
使用Linq
string text = "ABC 12345";
string toReplace = text.Split().SkipWhile(x => x == "ABC").First();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.