Saturday, March 31, 2012

String Tokenizing with ASP.NET?

Hi all,

I am somewhat new to the DOTNET world and I am wondering if there is an easy way to tokenize strings using asp.net.

With java, this is done quite easilly, but I have not seen anything in the .net class libraries that would work the same.

Any help is appreciated!

_Luke Dubya
_minneapolisOkay I'll be more specific:

I have cookies that have several values seperated by a comma ","

I want to parse the values into seperate tokens so I can then run a SQL statement with several OR statements to return the results in my datagrid.

the values of my cookies are product ids.

example: 4322-001,E322,8000DN,4317-001

Then I want to turn this into a sql statement:

SELECT * FROM sometable WHERE productid="4322-001" OR WHERE productid="E322" etc...

so thats what I'm trying to do. any ideas or help is much appreciated.

Thanks all!

_Luke Dubya
_Minneapolis
Substrings seems the best way to go (assume that you dont know how many product numbers you have in the cookie).

<a href"http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasssubstringtopic.asp">Here</a> is a link to set you off.

You want something on the lines of:


Dim cookieString as string = ......(get the cookie string)
Dim sqlStatement = "SELECT * FROM sometable "

if ( there is a "," in the cookieString)
{
sqlStatement += " WHERE productid = " & cookieString.substring(...)
cookieString = cookieString.substring(...) 'get rid of the first product and ","
}

where ( there is a "," in the cookieString)
{
sqlStatement += " OR WHERE productid = " & cookieString.substring(...)
cookieString = cookieString.substring(...) 'get rid of the first product and ","
}

HTH

Jagdip

0 comments:

Post a Comment