Read-only archive of the All About Symbian forum (2001–2013) · About this archive

splitting a comma-separated list

1 replies · 1,991 views · Started 16 December 2004

Hi all

I receive data (sentences) in a buffer of fixed length (TBuf16 <80>😉. These sentences are comma-separated and each has a start marker and an end marker; however, the received sentences are not of fixed length and reading starts immediately and is continuous, resulting in something like this:


1: xxxx,xx,xx$^xxx,xx,xxx,..,xxx
2: xxx,xx,xx$^xxxx,xxxx,..,xxxxx
3: xx$^xxx,xxx,..,xx,xx$^xx,xxx,
4: xxxx,xxx,xx,xx,xx$^xxx,xxx,xx
and so forth (I think you get the idea)

[line numbers = string received during each read and not part of the string
^ = start marker of a sentence
$ = end marker of a sentence
x = alphanumeric character and/or a dot(.)
.. = any number of alphanumeric characters, dots or a comma]

I need the individual values (between the commas) in separate fields of an array, so that I can access them during run-time. In C++ I would use a vector, but Symbian doesn't support these and suggests dynamic arrays. I have never worked with these and was wondering if you can help me with the algorithm of setting these values in dynamic array fields.

Furthermore, I was wondering if there is a smart way of joining the individual sentences together. Each sentence starts with a ^ and ends with a $. It gets a bit tricky when a complete sentence is in one line (such as in line 3 above). I used 'Find' (from class TBuf16) to search for either ^ or $, but it only searches for the first occurence. In the example in line 3 there two (^ and $) each.

I guess the normal procedure would be to join the sentences first and then do any splitting up of the sentence values into array fields, right? Or, is there a on-the-fly filling procedure for dynamic arrays?

Once a complete sentence is there, I need certain values of it, process it in some way and then discard the sentence. (Well, I would like to store these sentences once they're received, yet I won't read them again - but that's a different story).

Thanks for all your valuable input and help!

Hi,

You can uses a HBufC8 for the same.This is a heap buffer.
Put all your data into this.Now we start parsing it

You limiters are ^ and $ as I understand.
Find the positions of both using Find()

now:
TBuf sBuf;
for(i = ^pos; i<$pos;i++)
{
sBuf.Append(IHeapBuf->operator[](i));
}

After extracting you can insert this into a Des Array.

Not sure if it helped..........