split strings.
-
Hi All, I have this string: "1x #234 Greenock Creek - Alice's - Shiraz - 2001 - 750mL = $578.05 1x #242 Greenock Creek - Cornerstone - Grenache - 2001 - 750mL = $297.55 2x #363 Maxwell - Ellen Street - Shiraz - 2002 - 750mL = $309.10 2x #369 Maxwell - Meracus 53 - Shiraz Grenache - 2002 - 750mL = $226.60" Now i want to split this string like this: 1x #234 Greenock Creek - Alice's - Shiraz - 2001 - 750mL = $578.05 1x #242 Greenock Creek - Cornerstone - Grenache - 2001 - 750mL = $297.55 2x #363 Maxwell - Ellen Street - Shiraz - 2002 - 750mL = $309.10 2x #369 Maxwell - Meracus 53 - Shiraz Grenache - 2002 - 750mL = $226.60 I was tring to load this string into an array of char, but the performance will be affected since i have a pretty large string input. Are there any other ways to split this string. Thanks very much.
-
Hi All, I have this string: "1x #234 Greenock Creek - Alice's - Shiraz - 2001 - 750mL = $578.05 1x #242 Greenock Creek - Cornerstone - Grenache - 2001 - 750mL = $297.55 2x #363 Maxwell - Ellen Street - Shiraz - 2002 - 750mL = $309.10 2x #369 Maxwell - Meracus 53 - Shiraz Grenache - 2002 - 750mL = $226.60" Now i want to split this string like this: 1x #234 Greenock Creek - Alice's - Shiraz - 2001 - 750mL = $578.05 1x #242 Greenock Creek - Cornerstone - Grenache - 2001 - 750mL = $297.55 2x #363 Maxwell - Ellen Street - Shiraz - 2002 - 750mL = $309.10 2x #369 Maxwell - Meracus 53 - Shiraz Grenache - 2002 - 750mL = $226.60 I was tring to load this string into an array of char, but the performance will be affected since i have a pretty large string input. Are there any other ways to split this string. Thanks very much.
You can do this with a fairly naive regex. I'm no regex expert, but I quickly knocked this one together which should satisfy your requirements here:
Regex regex = new Regex(
@"\d+x\s\#\w*[^$]+\$\d+\.\d+",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.ExplicitCapture
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
You can do this with a fairly naive regex. I'm no regex expert, but I quickly knocked this one together which should satisfy your requirements here:
Regex regex = new Regex(
@"\d+x\s\#\w*[^$]+\$\d+\.\d+",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.ExplicitCapture
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Thanks for your posting, but you regular expression is not working. and this is supposed to be: @"([0-9][x]\s#[0-9]+\s[A-Z,a-z,\s,',0-9]+\s-\s[A-Z,a-z,\s,',0-9]+\s-\s[A-Z,a-z,\s,',0-9]+\s-\s[0-9]+\s-\s[0-9]+mL\s=\s[$][0-9,.]+)", but it is verbose, and i need to refine it.
-
Hi All, I have this string: "1x #234 Greenock Creek - Alice's - Shiraz - 2001 - 750mL = $578.05 1x #242 Greenock Creek - Cornerstone - Grenache - 2001 - 750mL = $297.55 2x #363 Maxwell - Ellen Street - Shiraz - 2002 - 750mL = $309.10 2x #369 Maxwell - Meracus 53 - Shiraz Grenache - 2002 - 750mL = $226.60" Now i want to split this string like this: 1x #234 Greenock Creek - Alice's - Shiraz - 2001 - 750mL = $578.05 1x #242 Greenock Creek - Cornerstone - Grenache - 2001 - 750mL = $297.55 2x #363 Maxwell - Ellen Street - Shiraz - 2002 - 750mL = $309.10 2x #369 Maxwell - Meracus 53 - Shiraz Grenache - 2002 - 750mL = $226.60 I was tring to load this string into an array of char, but the performance will be affected since i have a pretty large string input. Are there any other ways to split this string. Thanks very much.
-
Hi All, I have this string: "1x #234 Greenock Creek - Alice's - Shiraz - 2001 - 750mL = $578.05 1x #242 Greenock Creek - Cornerstone - Grenache - 2001 - 750mL = $297.55 2x #363 Maxwell - Ellen Street - Shiraz - 2002 - 750mL = $309.10 2x #369 Maxwell - Meracus 53 - Shiraz Grenache - 2002 - 750mL = $226.60" Now i want to split this string like this: 1x #234 Greenock Creek - Alice's - Shiraz - 2001 - 750mL = $578.05 1x #242 Greenock Creek - Cornerstone - Grenache - 2001 - 750mL = $297.55 2x #363 Maxwell - Ellen Street - Shiraz - 2002 - 750mL = $309.10 2x #369 Maxwell - Meracus 53 - Shiraz Grenache - 2002 - 750mL = $226.60 I was tring to load this string into an array of char, but the performance will be affected since i have a pretty large string input. Are there any other ways to split this string. Thanks very much.
Here's a RegEx:
(?'Quantity'\d+)x #(?'Number'\d+) (?'Winery'[^-]+)- (?'Brand'[^-]+)- (?'Type'[^-]+)- (?'Year'\d+) - (?'Size'[^=]+)= (?'Price'[0-9$\.]+)
Some of the values may need trimming.