01-03-2013 05:17 PM - edited 01-03-2013 05:18 PM
Usually in these situations, things can be simplified so I figured I'd come here to ask if anyone sees a better way. I basically have some delimiters (which may or not be in the search string string) and I need to grab the text between each set of delimiters. The search and replace is probably inefficient, at best, and it would be nice to stick it all in one loop, possibly using shift registers but I couldn't quite get it working as I wanted.
01-03-2013 05:49 PM - edited 01-03-2013 05:52 PM
01-03-2013 05:52 PM - edited 01-03-2013 05:56 PM
A slightly modified version of Christen's which will allow the last item to have a delimiter after it. The above version will give you an empty string in the last entry of the array.
01-03-2013 05:58 PM
@Mark_Yedinak wrote:
A slightly modified version of Christen's which will allow the last item to have a delimiter after it. The above version will give you an empty string in the last entry of the array.
Mine works fine with the given default data. 😄
If you know that you are always looking 2 items, you can even use a FOR loop for even better efficiency. 😉
01-03-2013 06:00 PM - edited 01-03-2013 06:02 PM
@altenbach wrote:
@Mark_Yedinak wrote:
A slightly modified version of Christen's which will allow the last item to have a delimiter after it. The above version will give you an empty string in the last entry of the array.
Mine works fine with the given default data. 😄
If you know that you are always looking 2 items, you can even use a FOR loop for even better efficiency. 😉
I tried both since Greg mentioned the delimiter may or may not be there. My first attempt was exactly the same as yours. I modified after I added the last delimiter.
I also tried to use a regular expression. It would work provided you didn't have any longer delimiters which contained a shorter delimiter such as the "P" and "1P".
01-03-2013 06:11 PM
01-03-2013 06:28 PM - edited 01-03-2013 06:31 PM
Well, this code is not the same, for example if you have consecutive delimiters, you generate empty elements while scan string for tokes contracts successive delimiters into one by default.
For example with an input string of "P34a1PPPP9ac"
I still get [34a, 9ac] while you would get [34a, (blank), (blank), (blank), 9ac]
(Of course we don't have enough information to decide what's correct .... ;))
(... maybe if this idea would get implemented .... ;))
01-03-2013 07:12 PM
Add a '+' to the end of the regex, problem solved.
01-04-2013 12:54 AM
01-04-2013 12:58 AM - edited 01-04-2013 01:01 AM
@altenbach wrote:
I still get [34a, 9ac] while you would get [34a, (blank), (blank), (blank), 9ac]
(Of course we don't have enough information to decide what's correct .... ;))
Thanks guys. These delimeters are gotten from a specific barcode standard and act as prefixed idenifiers on the following data. Encoding will have been done on the data so I believe I shouldn't have consecutive delimiters. I have to assume the encoding takes care of all this, to avoid the issues of the data itself containing any character strings that match standardized identifiers, as this could confuse any parser (although I haven't read up on it much to this point so I don't know for sure yet). This is more than enough to get me started. Appreciate it.