|
|
|
You can often use the Replace function in a smewhat unorthodox ways to simplify (and sometimes optimize) your code. For example, in order to count the number of occurrences of a substring inside another string you usually need a loop based on the InStr function: |
Here's is a one-liner that does exactly the same. The trick is to replace each substring with another string that is one character longer, and then determine the difference between the obtained string and the original string. This number is equal to the number of substitutions done, and therefore equal to the number of substrings found. (Note that the code is more concise but a little slower than the previous approach). |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|