Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2007, 03:41 PM
Authorized User
 
Join Date: Feb 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default any shorter way to get the same result ?

i have a string Series = "C423S539L12332K656GN"
i want to find out the result for C, S, L, K and G
and the result should be
C = 423
S = 539
L = 12332
K = 656
G = N

and here is what i did:

        C = Mid(Series, InStr(Series, "C") + 1, InStr(Series, "S") - 2)
        S = Mid(Series, InStr(Series, "S") + 1, InStr(Series, "L") - (InStr(Series, "S") + 1))
        L = Mid(Series, InStr(Series, "L") + 1, InStr(Series, "K") - (InStr(Series, "L") + 1))
        K = Mid(Series, InStr(Series, "K") + 1, InStr(Series, "G") - (InStr(Series, "K") + 1))
        G = Right(Series, 1)


my question is do way have any shorter way to get the same result ?
thanks



 
Old June 28th, 2007, 05:22 AM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could probably do this using a regular expression to split the string. Something along the lines of:

Regex r=new Regex("[A-Z]+[0-9]+");
string Series="C423S539L12332K656GN";
String[] myStringSplit=r.Split(Series);

This will create a regular expression that looks for one or more captial letters followed by one or more numbers, then split the series string on each match into a string array called myStringSplit.

The regular expression may be wrong, I didn't have time to test this and its not my strong point :-)

Hope this helps!


 
Old June 28th, 2007, 07:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

A regular expresion would be more slow than your aproach... what do you mean by shorter way?? less code???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old July 2nd, 2007, 01:18 PM
Authorized User
 
Join Date: Feb 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what do you mean by shorter way?? less code??? -> less code and faster load
thanks


 
Old July 2nd, 2007, 03:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. a good idea will be to replace mid and instr with string functions, look into the string class to find what you need... and less code doesn't mean that the load will be faster.. you can writte all the code in one line and it could be slower than this...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old July 3rd, 2007, 08:02 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

hmmm one approach would be:

string[] arrValues = Series.Split(new char[] {'C', 'S', 'L', 'K', 'G'});

Your array now looks like this:
arrValues[0] = 423
arrValues[1] = 539
arrValues[1] = 12332
arrValues[3] = 656
arrValues[4] = N

hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Result of Transformation PKHG BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 4 August 6th, 2008 10:57 AM
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
How many Result? Mantis PHP Databases 1 April 15th, 2005 03:37 PM
keyword doesn't appear with result gilgalbiblewheel Classic ASP Databases 2 January 11th, 2005 12:45 AM
Result set jemacc SQL Server 2000 0 December 19th, 2003 07:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.