Click here to Skip to main content
15,845,912 members
Home / Discussions / C#
   

C#

 
GeneralRe: Common Variables in Main, Dlls, and Functions in .cs Pin
zequion8-Jan-17 6:42
professionalzequion8-Jan-17 6:42 
QuestionMocking Controller Methods Pin
Liagapi7-Jan-17 14:34
Liagapi7-Jan-17 14:34 
AnswerRe: Mocking Controller Methods Pin
Richard MacCutchan7-Jan-17 21:52
mveRichard MacCutchan7-Jan-17 21:52 
GeneralRe: Mocking Controller Methods Pin
Liagapi7-Jan-17 22:10
Liagapi7-Jan-17 22:10 
GeneralRe: Mocking Controller Methods Pin
Eddy Vluggen8-Jan-17 3:42
professionalEddy Vluggen8-Jan-17 3:42 
AnswerRe: Mocking Controller Methods Pin
Member 128317728-Jan-17 20:15
Member 128317728-Jan-17 20:15 
GeneralRe: Mocking Controller Methods Pin
Liagapi11-Jan-17 6:24
Liagapi11-Jan-17 6:24 
QuestionI want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 6:16
professionalMember 105306516-Jan-17 6:16 
I want to replace number in two tag to double with regex in a file txt


I am bit confused writing the regex for finding the Text between the two delimiters <pre><TD</TD> 
and replace the text with another text in c#,how to replace?
pop.txt:

<TD>25</TD> 

<To>74</TD> 

<Ti>30</TD> 

<TD>45</TD> 

<TD>19</TD> 
<TD>25</TD> 

<To>74</TD> 

<Ti>30</TD>


Result of my code


<pre><TD>2500,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00</TD> 


<to>7400,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

<ti>30
<ti>30
45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

19,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
25

<to>74

<ti>30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00



my code:

C#
<pre> string text = File.ReadAllText("pop.txt");
               
            try
            {

                //  text = text.Replace("some text", "new value");

                //..............................................................
                //  string test = textBox4.Text;
                // string test = @"<TR> <TD>1Q Ene</TD> <TD>3.08%</TD> </TR><TR> <TD>1Q Ene</TD> <TD>3.08%</TD> </TR><TR> <TD>1Q Ene</TD> <TD>3.08%</TD> </TR>";

                //  string test = textBox4.Text;
                // string test = " data-video-ids=68888</mtBrutSommes>";
                string pattern = @"(<TD>(.+?)</TD>)";
                // string pattern = @"(?<=\\<TD\\>)(\\s*.*\\s*)(?=\\<\\/TD\\>)";
                var matches = Regex.Matches(text, pattern);

                var result = (from Match m in matches select (m.Groups[2].ToString())).ToList<string>();
              
                //textBox4.Text = "";
                foreach (var item in result)
                {
                  var a = Convert.ToDouble(item).ToString("#,##.00");
                    string s = String.Format("{0:0.##}", item); 
                    //textBox4.Text += a  + Environment.NewLine;

                    text = text.Replace(item,a);
                   
                   
                }

            }
            catch (Exception ex)
            {
                // MessageBox.Show(ex.Message);
                //return;
            }
            File.WriteAllText("resultat.txt", text);

AnswerRe: I want to replace number in two tag to double with regex in a file txt Pin
OriginalGriff6-Jan-17 6:34
mveOriginalGriff6-Jan-17 6:34 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 8:03
professionalMember 105306516-Jan-17 8:03 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
OriginalGriff6-Jan-17 9:06
mveOriginalGriff6-Jan-17 9:06 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 9:35
professionalMember 105306516-Jan-17 9:35 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
OriginalGriff6-Jan-17 9:49
mveOriginalGriff6-Jan-17 9:49 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 10:04
professionalMember 105306516-Jan-17 10:04 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
OriginalGriff6-Jan-17 10:26
mveOriginalGriff6-Jan-17 10:26 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 10:59
professionalMember 105306516-Jan-17 10:59 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
OriginalGriff6-Jan-17 11:40
mveOriginalGriff6-Jan-17 11:40 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 11:49
professionalMember 105306516-Jan-17 11:49 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Dave Kreskowiak6-Jan-17 12:15
mveDave Kreskowiak6-Jan-17 12:15 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 12:29
professionalMember 105306516-Jan-17 12:29 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Dave Kreskowiak6-Jan-17 12:33
mveDave Kreskowiak6-Jan-17 12:33 
GeneralRe: I want to replace number in two tag to double with regex in a file txt Pin
Member 105306516-Jan-17 12:37
professionalMember 105306516-Jan-17 12:37 
QuestionC# Get random object form JSON File Pin
Pavlex44-Jan-17 8:22
Pavlex44-Jan-17 8:22 
AnswerRe: C# Get random object form JSON File Pin
NotPolitcallyCorrect4-Jan-17 8:41
NotPolitcallyCorrect4-Jan-17 8:41 
GeneralRe: C# Get random object form JSON File Pin
Gerry Schmitz4-Jan-17 8:59
mveGerry Schmitz4-Jan-17 8:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.