c# - Most efficient way of splitting many strings -


my current project handles large numbers of incoming radio messages (~5m per day) represented strings must divided pre-determined sized chunks, ready storage.

for example, message come in following format:

mziiiiccssss

each different char represents chunk, example holds 5 chunks (m, z, iiii, cc, ssss).

an example of message using format be:

.91234ne0001 (., 9, 1234, ne, 0001)

i've used substring far have been told not efficient regular expressions. if case, how can use regex match @ char positions, instead of semantic pattern?

substring faster regex. since trying separate string fixed-size chunks, use substring.


chao's comment gave me idea. use string(char[], int, int) constructor, this:

string message = ".91234ne0001"; char[] messagearr = message.tochararray(); string chunk1 = new string(messagearr, 0, 1); string chunk2 = new string(messagearr, 1, 1); string chunk3 = new string(messagearr, 2, 4); string chunk4 = new string(messagearr, 6, 2); string chunk5 = new string(messagearr, 8, 4); 

you can give variables better names :)

this manual way of doing substring doing. thought faster substring method, thinking of wrong approach previously. same speed.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -