Saturday, March 31, 2012
string to object
can use a string parameter to pass into the selectmethod. so I pass in a
string = 'Dog' now once in the selectmethod I need to convert that string
into and object of type Dog...I hope this makes sense. Do anyone know how to
do this' i guess I need a similar method to Eval in javascript.
Please need urgent so could replies also go to johncotsell@dotnet.itags.org.hotmail.com
cheers John"John Cotsell" <john.cotsell@.formicary.net> wrote in
news:epLI7fRHGHA.1192@.TK2MSFTNGP11.phx.gbl:
> Basically I have a class called Dog and when using the
> objectdatasource I can use a string parameter to pass into the
> selectmethod. so I pass in a string = 'Dog' now once in the
> selectmethod I need to convert that string into and object of type
> Dog...I hope this makes sense. Do anyone know how to do this'
System.Type.GetType can return objects based on Type.
> Please need urgent so could replies also go to johncotsell@.hotmail.com
If you post on Usenet, check on Usenet.
Stan Kee (spamhoneypot@.rogers.com)
For equivalent to javascript's eval, check out the namespaces
System.Reflection.Emit (for creating assemblies on-the-fly) or perhaps
Microsoft.CSharp.Compiler (try the static Compile() method)
string to object
can use a string parameter to pass into the selectmethod. so I pass in a
string = 'Dog' now once in the selectmethod I need to convert that string
into and object of type Dog...I hope this makes sense. Do anyone know how to
do this?? i guess I need a similar method to Eval in javascript.
Please need urgent so could replies also go to johncotsell@dotnet.itags.org.hotmail.com
cheers JohnFor equivalent to javascript's eval, check out the namespaces
System.Reflection.Emit (for creating assemblies on-the-fly) or perhaps
Microsoft.CSharp.Compiler (try the static Compile() method)
Wednesday, March 28, 2012
String.Equals Wrong Parameter ?
Thanks
Mike Thomas
1 Dim sb As New StringBuilder("abcd")
2 Dim str1 As [String] = "abcd"
3 Dim str2 As [String] = Nothing
4 Dim o2 As [Object] = Nothing
5 ? str1.Equals(sb)
6 ? str1.Equals(o2)
7 ? str1.Equals(str2)
8 ? [String].Equals(str1, str2)
At top is
Imports System.String
Imports System.TextHi,
my guess would be that you have Option Strict set to On so that you have to cast specifically. Try something like this:
str1.Equals(sb.ToString)
Grz, Kris.
Many thanks Kris - that was exactly it.
Mike Thomas
Monday, March 26, 2012
String.Split with multi character delimiter
parameter. Rather than declaring a String, you need to declare a char array,
and work with that. Example:
Dim delString As String = "#|#"
Dim del As Char() = delString.ToCharArray()
...
s = source.Split(del)
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"PCK" <anonymous@dotnet.itags.org.discussions.microsoft.com> wrote in message
news:3CCCD026-B1BB-4F2D-8DE2-7D3BD398127F@dotnet.itags.org.microsoft.com...
> Hi,
> I have a string that I would like split into a single dimension string
array. The source string has a multi character delimiter. It appears that
string.split(delimiter) only splits based on the first character of the
delimiter.
> For example:
> Dim s() As String
> Dim source As String
> Dim del As String
> del = "#!#"
> source = "ABC#!#DEF#!#GHI"
> s = source.Split(del)
> s(0) = "ABC"
> s(1) = "!"
> s(2) = "DEF"
> s(3) = "!"
> s(4) = "GHI"
> Where as I would like the following returned. Does anyone know of a built
in function to do this?
> s(0) = "ABC"
> s(1) = "DEF"
> s(2) = "GHI"
> Thanks.
> PCKKevin, thanks for the response
I had thought about that earlier. Actually what happens when you use a char array is that it splits based on any item in the array not on the concatenation of all items in the array
Do you have any other suggestions.
myString.Replace( "#!#", "!" ).Split ( "!" ); ?
Dan.
"PCK" <anonymous@.discussions.microsoft.com> wrote in message
news:3F0E32B3-4C65-4AA2-A1A2-110F0644FA6A@.microsoft.com...
Kevin, thanks for the response.
I had thought about that earlier. Actually what happens when you use a char
array is that it splits based on any item in the array not on the
concatenation of all items in the array.
Do you have any other suggestions.
> I had thought about that earlier. Actually what happens when you use a
char array is that it splits based on any item in the array not on the
concatenation of all items in the array.
Oops. Sorry. That's true. Well, you could always use the Visual Basic.Net
Split() method (function), which takes a string as an argument.
Alternatively, you could try Daniel's solution.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"PCK" <anonymous@.discussions.microsoft.com> wrote in message
news:3F0E32B3-4C65-4AA2-A1A2-110F0644FA6A@.microsoft.com...
> Kevin, thanks for the response.
> I had thought about that earlier. Actually what happens when you use a
char array is that it splits based on any item in the array not on the
concatenation of all items in the array.
> Do you have any other suggestions.
the problem is the split method is not intended for use with string
seperators, to do one that works properly, you'd have to write one yourself.
alternatively, if there is a character you know (think highly likely) will
NOT appear in your text, use the replace method to convert to that character
as a seperator, then split.
hope that helps.
Dan.
"PCK" <anonymous@.discussions.microsoft.com> wrote in message
news:A6A5A7D8-5BB1-46D7-BC35-ABD8DD55130E@.microsoft.com...
Dan, thanks for the response.
But what if the data was "ABC#!#D!EF#!#GHI"
That would split it out as
ABC
D
EF
GHI
versus
ABC
D!EF
GHI
The VB Split method is what I was looking for. Thanks for the help.
StringBuilder AppendFormart cannot handle String!
If I use AppendFormat with string as a parameter.
I get string cannot be converted to IFormatProvider.
This occurs in 2.0
Thanks.
JayIt might be the actual format that's invalid, not the parameter. Perhaps an
example of code that doesn't work would help...
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jay Balapa" <jbalapa@.hotmail.com> wrote in message
news:eZplPbsGGHA.1100@.TK2MSFTNGP10.phx.gbl...
> Hello,
> If I use AppendFormat with string as a parameter.
> I get string cannot be converted to IFormatProvider.
> This occurs in 2.0
> Thanks.
> Jay
StringBuilder AppendFormart cannot handle String!
If I use AppendFormat with string as a parameter.
I get string cannot be converted to IFormatProvider.
This occurs in 2.0
Thanks.
JayIt might be the actual format that's invalid, not the parameter. Perhaps an
example of code that doesn't work would help...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Jay Balapa" <jbalapa@.hotmail.com> wrote in message
news:eZplPbsGGHA.1100@.TK2MSFTNGP10.phx.gbl...
> Hello,
> If I use AppendFormat with string as a parameter.
> I get string cannot be converted to IFormatProvider.
> This occurs in 2.0
> Thanks.
> Jay
>