how to compare whetther a substring is available in striong or not
-
exactly waht i want to do i want to check that whether a particular string is in the string or not? like str ="C:\Inetpub\wwwroot\medicaps"; now i want ot check whether a wwwroot is in this string or not. thanx
-
exactly waht i want to do i want to check that whether a particular string is in the string or not? like str ="C:\Inetpub\wwwroot\medicaps"; now i want ot check whether a wwwroot is in this string or not. thanx
Perhaps you would like to listen to the advice given on your last post before asking the same question again. X| :rolleyes:
only two letters away from being an asset
-
exactly waht i want to do i want to check that whether a particular string is in the string or not? like str ="C:\Inetpub\wwwroot\medicaps"; now i want ot check whether a wwwroot is in this string or not. thanx
-
exactly waht i want to do i want to check that whether a particular string is in the string or not? like str ="C:\Inetpub\wwwroot\medicaps"; now i want ot check whether a wwwroot is in this string or not. thanx
Hi here is the way, we can use "IndexOf" string class method. string strTest = "I am strong"; if(strTest.IndexOf("strong")==0) { return(false); } Ram
-
Hi here is the way, we can use "IndexOf" string class method. string strTest = "I am strong"; if(strTest.IndexOf("strong")==0) { return(false); } Ram
Using IndexOf will work but the System.Text.RegularExpressions is a better way, here is an example.
Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean Dim r As Regex = New Regex(Value, RegexOptions.IgnoreCase) Dim m As Match = r.Match(Line) If m.Success Then Return True Else Return False End Function
-
Using IndexOf will work but the System.Text.RegularExpressions is a better way, here is an example.
Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean Dim r As Regex = New Regex(Value, RegexOptions.IgnoreCase) Dim m As Match = r.Match(Line) If m.Success Then Return True Else Return False End Function
Why not just use .Contains()?
-
Why not just use .Contains()?
To the best of my knowledge .Contains is not available to string variables. It is for ArrayList and other Collection objects. If this is wrong could you please show me an example?
-
To the best of my knowledge .Contains is not available to string variables. It is for ArrayList and other Collection objects. If this is wrong could you please show me an example?
-
Using IndexOf will work but the System.Text.RegularExpressions is a better way, here is an example.
Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean Dim r As Regex = New Regex(Value, RegexOptions.IgnoreCase) Dim m As Match = r.Match(Line) If m.Success Then Return True Else Return False End Function
If you need the added functionality that the regular expression offers, it's a better way. If you don't, the IndexOf way is more efficient. You forgot to escape the value, by the way. And I really don't see the reason to check the value of Success before returning it... ;)
Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean
Dim r As Regex = New Regex(Regex.Escape(Value), RegexOptions.IgnoreCase)
Dim m As Match = r.Match(Line)
Return m.Success
End Function--- b { font-weight: normal; }
-
If you need the added functionality that the regular expression offers, it's a better way. If you don't, the IndexOf way is more efficient. You forgot to escape the value, by the way. And I really don't see the reason to check the value of Success before returning it... ;)
Private Function InLine(ByVal Line As String, ByVal Value As String) As Boolean
Dim r As Regex = New Regex(Regex.Escape(Value), RegexOptions.IgnoreCase)
Dim m As Match = r.Match(Line)
Return m.Success
End Function--- b { font-weight: normal; }
I'm still working with 1.1 so that is good to know when I move to 2.0 – thank you. I see your point with using the IndexOf and agree it will provide better performance then the function.