hi, I'm wondering about the performance of regular expression on different scenario, and if it would be better to go with substrings and/or stringbuilder class
I'm trying to cycle through crystal report objects and find fields that contain text and replace them with the datatable m_dtData, which contains 2 columns, the id and the message. So based on the situation, i cannot use my main regex and do a replace right away since i dont know what i have to replace it with since it depends on a datatable field, so i have to create a second regex and i was wondering about performance issues, for a regex like "\{[0-9]+\}", should i use the stringbuilder class and do manual replaces or regex would be faster... And I'm not 100% sure that i'm using the regex in the correct way to do what i want to do.
VB.NET:
Private m_objRegexStrReplace As Regex = New Regex("\{[0-9]+\}")
For Each objMatch As Match In m_objRegexStrReplace.Matches(strObjectText)
Try
drResults = m_dtData.Select("ID = " & objMatch.Value.Substring(1, objMatch.Length - 2))
strDatabaseString = drResults(0).Item("cString")
objSpcRegex = New Regex("\{" & objMatch.Value.Substring(1, objMatch.Length - 2) & "\}")
strObjectText = objSpcRegex.Replace(strObjectText, strDatabaseString, 1)
Catch
'ID Not found in database
MessageBox.Show("Id not found in DB")
End Try
Next
r_cr_TextObj.Text = strObjectText
I'm trying to cycle through crystal report objects and find fields that contain text and replace them with the datatable m_dtData, which contains 2 columns, the id and the message. So based on the situation, i cannot use my main regex and do a replace right away since i dont know what i have to replace it with since it depends on a datatable field, so i have to create a second regex and i was wondering about performance issues, for a regex like "\{[0-9]+\}", should i use the stringbuilder class and do manual replaces or regex would be faster... And I'm not 100% sure that i'm using the regex in the correct way to do what i want to do.