none
How do I get rid of the error "Input string was not in the correct format." in the following code? RRS feed

  • Question

  • TempSectionStringArray = TempSectionString.Split(' ');
                                    TempSectionTitleArray = TempSectionTitleString.Split(' ');
                                    bool SectionsWritten = false;
                                    for (var icm = 0; icm < TempSectionTitleArray.Length; icm++)
                                    {
                                        if (!string.IsNullOrEmpty(TempSectionTitleArray[icm]))
                                        {
                                            int tSectionNo = Convert.ToInt32(Regex.Match(TempSectionTitleArray[icm], @"(.+)|").Groups[1].Value); //Error here
                                            string tSectionTitle = Convert.ToString(Regex.Match(TempSectionTitleArray[icm], @"|(.+)").Groups[1].Value).Trim(' ');
                                            string TStrSectionHead = "";
                                            TStrSectionHead = StrSectionHead;
                                            TStrSectionHead = Regex.Replace(TStrSectionHead, "<div class=\"sectionName\">" + TitleTextBox.Text + "</div>", "<div class=\"sectionName\">" + tSectionTitle + "</div>", RegexOptions.Multiline);
    

    Saturday, May 26, 2018 6:15 AM

All replies

  • Try using an appropriate regular expression, maybe “.*?\|” or “\d+\|”, depending on specific details, not shown yet.


    Saturday, May 26, 2018 7:19 AM
  • int tSectionNo = Convert.ToInt32(Regex.Match(TempSectionTitleArray[icm], "(.+)\\|").Groups[1].Value);

    I even tried this, but it did not help.

    Saturday, May 26, 2018 7:29 AM
  • Dim tSectionNo As Integer = CInt(Regex.Match(TempSectionTitleArray(icm), "(.+)\|").Groups(1).Value)

    This worked in Visual Basic.

    Saturday, May 26, 2018 7:55 AM