PDA

View Full Version : DotNet Find String


Panayot
06-10-2011, 07:04 PM
Hi to all, its my first call for help here.
Shortly, i want to find string (in .net-string) with ignore case.
Convert .net-string to mxs-string is not an option in my case.
-- example code:
s1 = dotNetObject "System.String" "Hello World!"
s2 = dotNetObject "System.String" "world"
s3 = dotNetObject "System.String" "World"

s1.IndexOf (s2) >= 0 -- false
s1.IndexOf (s3) >= 0 -- true

-- can solve it with ToLower/LCase but that's not always a good idea
-- in C# i can say: (s1.IndexOf(s2, StringComparison.OrdinalIgnoreCase) >= 0)
-- but i try to set CompareOptions in Mxs and fail somehow...

com = dotNetClass "System.Globalization.CompareInfo"
opt = dotNetClass "System.Globalization.CompareOptions"

s1.IndexOf s2 opt.OrdinalIgnoreCase
-- Runtime error: No method found which matched argument list

com.IndexOf s1 s2 opt.OrdinalIgnoreCase
-- Runtime error: dotNet runtime exception: Non-static method requires a target.
Thanks in advance for any help

denisT
06-10-2011, 07:10 PM
s1 = dotNetObject "System.String" "Hello World!"
s2 = dotNetObject "System.String" "world"
s3 = dotNetObject "System.String" "World"

s1.Indexof "world" (dotnetclass "System.StringComparison").OrdinalIgnoreCase
s1.Indexof s2 (dotnetclass "System.StringComparison").OrdinalIgnoreCase
s1.Indexof "World"
s1.Indexof s3

Panayot
06-10-2011, 07:18 PM
s1.Indexof "world" (dotnetclass "System.StringComparison").OrdinalIgnoreCase
s1.Indexof s2 (dotnetclass "System.StringComparison").OrdinalIgnoreCase
Many thanks Denis !

CGTalk Moderation
06-10-2011, 07:18 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.