How to search a string in a given string. Is there any inbuilt service in webmethod integration server…??
For example:
I have a string input: I am a developer for local tech.
and I have to search in the above string whether that contains ‘local’ or not.
The search should be like ignore case.
You can use the built-in service called “indexOf” as well. This service starts the search from position 0 of the input string, unless you give it a starting position. It will only return the position of the first occurrence of the searchString “local”.
So do the following if you have need to track how many times “local” is present -
Calculate the length of the string “local”
Since case does not matter to you, use “toLower” build-in service to get the lowercase equivalents of both the input and search strings
Call indexOf and pass the input string, searchString, position (first time it will be 0)
Note down the current position of searchString (i.e., “local” in your case), returned by indexOf
Add the position and length values together, to calculate a new starting point (not 0th position) for the search
Pass new starting position to indexOf, to get the next occurrence (this will be done using “Repeat”)
Keep a track of all the positions separately (concatenate)
Note that position will be one value less than length, numerically, so calculate the right starting point in step 5. With “encoding” values, you can use this for other languages such as Japanese, Chinese as well.
I don’t know. I’ve never profiled these 2 approaches. I doubt the difference between them will matter in a significant way, depending upon what you’re doing. Don’t optimize prematurely – measure/profile to see if for the overall flow it is “fast enough.” If it is, you’re done. If not, then profile to see where the time is being spent and optimize that if possible. More often than not, the things that get optimized based upon opinion that it will be faster turn out to make no difference at all.