|
-
Feb 6th, 2007, 09:37 PM
#1
Thread Starter
New Member
-
Feb 6th, 2007, 09:40 PM
#2
Member
Re: [02/03] INSTR() Function
for .net use the string.contains or instr(string,pattern) <> 0
-
Feb 6th, 2007, 09:46 PM
#3
Thread Starter
New Member
Re: [02/03] INSTR() Function
 Originally Posted by wrecklesswun
for .net use the string.contains or instr(string,pattern) <> 0
Yeah but that only searches for string1 anywhere in the string2. Is there a way I can find out if string1 is the beginning of string2? Or another way of putting, if string2 begins with string1
-
Feb 6th, 2007, 09:53 PM
#4
Re: [02/03] INSTR() Function
Don't use Runtime functions unless they add value. InStr doesn't. You want to do something with a String object, you go to the MSDN help topic for the member listing of the String class. There you find StartsWith, EndsWith and IndexOf. Contains is new in .NET 2.0 and can be replaced in .NET 1.x with IndexOf <> -1
-
Feb 6th, 2007, 09:55 PM
#5
Re: [02/03] INSTR() Function
Use a combination of IndexOf() and SubString() which are both methods of the string object.
IndexOf() returns an integer value of where in the string, the specified substring is found. It returns the index of the first character in the found string.
SubString() is used to return a portion of a given string.
So once you know where in the string the substring you are looking for starts (by using indexof) you can then use substring to pull out the string you want.
-
Feb 6th, 2007, 10:36 PM
#6
Thread Starter
New Member
Re: [02/03] INSTR() Function
Thanks for the replies!! The String.StartsWith worked great!!!
-
Feb 7th, 2007, 01:48 AM
#7
Member
Re: [02/03] INSTR() Function
 Originally Posted by jmcilhinney
Don't use Runtime functions unless they add value. InStr doesn't. You want to do something with a String object.
What do you mean by a runtime function?
What are the benefits from using the string object?
I assume VAL() is a runtime function. So how should I rewrite something like:
intAnswer = VAL(strA) + VAL(strB)
-
Feb 7th, 2007, 02:29 AM
#8
Re: [02/03] INSTR() Function
 Originally Posted by ghall426
What do you mean by a runtime function?
What are the benefits from using the string object?
I assume VAL() is a runtime function. So how should I rewrite something like:
intAnswer = VAL(strA) + VAL(strB)
I mean functions that rae part of the VB.NET Runtime, which basically means all the VB6 functions carried over into VB.NET so that (a) upgraded VB6 code will still work and (b) VB6 developers don't get grumpy because they have to type MessageBox.Show instead of MsgBox. Most Runtime functions have an alternative in a System-based namespace that is as good or better, so using VB6-style code just doesn't make sense.
There are certain situations where a Runtime function can add value and Val() can be one of those, although not always. For instance, the .NET Framework provides numerous ways to convert a string to a number and they should be used in preference in most situations. An occasion where Val() is useful is when you have a string like "27 kg" and you want to get just the number from the beginning. Val() will do that in one line where System-based types and members would take several. Having said that, Val() is vastly INFERIOR in many other situations. For instance, let's say that the user enters a numerical value in a TextBox and you want to convert that to a number and save it. If the user was to accidentally input "123o456" then Val() would convert that to 123 and you'd be saving completely the wrong value when the user meant 1230456. You could use IsNumeric to test it first but guess what: IsNumeric calls Double.TryParse internally. What you should do is call the TryParse method of the appropriate numeric type explicitly.
-
Mar 12th, 2007, 07:09 PM
#9
Member
Re: [02/03] INSTR() Function
it all boils down to the same low level machine call as well, correct? either the using the .net framework, you are steps removed from the processor or at least the os. Native code is the only direct method next to assembly
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|