0

I have a problem about using c# in word automation. My problem is I want to replace part of text in a textbox, ex: "ABC 12345" and replace 12345 by "123", as a result, "ABC 123" But I don't know how to get part of text in textbox, I use

object firstshape = 1;
string text = w_Doc.shapes.get_Item(ref firstshape).TextFrame.TextRange.Text;

to get the original text in textbox,but i don't know how to get the range of part text. Is there any solution to get any range of text in textbox? thanks a lot in advance!!!

4

3 に答える 3

1

このように置換を使用できます

    string Replace = "12345"; 
    string ReplaceWith = "123"
    text = text.Replace("12345","123")
于 2013-02-19T06:39:21.703 に答える
0

最後の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
于 2013-02-19T07:00:22.847 に答える
0

Linq を使用する

string text = "ABC 12345";
string toReplace = text.Split().SkipWhile(x => x == "ABC").First();
于 2013-04-16T12:45:36.880 に答える