Hi Experts:

I have a string which will always be in the format below:
"<string1><string2><string3>"

Any of string1, string2 and string3 could be null, and their lengths is not
known.

Just wondering, if there is an easy way to parse the whole string and read
out string1, string2 and string3 into 3 strings?

Thanks for any idea on this!
Polaris

Re: Easy way to read out formated string ? by Victor

Victor
Wed Jun 07 15:14:14 CDT 2006

Polaris wrote:
> I have a string which will always be in the format below:
> "<string1><string2><string3>"
>
> Any of string1, string2 and string3 could be null, and their lengths
> is not known.
>
> Just wondering, if there is an easy way to parse the whole string and
> read out string1, string2 and string3 into 3 strings?

Read a character. As soon as you encounter an opening angle bracket,
call a function that would extract all characters up until (but not
including) the closing angle bracket and return you the position after
the closing angle bracket. Store the extracted string and proceed
with scanning from that position (unless at the end).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask



Re: Easy way to read out formated string ? by Polaris

Polaris
Wed Jun 07 17:07:28 CDT 2006

Thanks for your info and that is what I did.

I was wondering if there is something similar to sscanf() function which
allows me to simplify the work.

Thanks
Polaris

"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:eHFJz7miGHA.1276@TK2MSFTNGP03.phx.gbl...
> Polaris wrote:
>> I have a string which will always be in the format below:
>> "<string1><string2><string3>"
>>
>> Any of string1, string2 and string3 could be null, and their lengths
>> is not known.
>>
>> Just wondering, if there is an easy way to parse the whole string and
>> read out string1, string2 and string3 into 3 strings?
>
> Read a character. As soon as you encounter an opening angle bracket,
> call a function that would extract all characters up until (but not
> including) the closing angle bracket and return you the position after
> the closing angle bracket. Store the extracted string and proceed
> with scanning from that position (unless at the end).
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask
>



Re: Easy way to read out formated string ? by Tim

Tim
Thu Jun 08 02:02:49 CDT 2006

"Polaris" <etpolaris@hotmail.com> wrote:
>
>I have a string which will always be in the format below:
>"<string1><string2><string3>"
>
>Any of string1, string2 and string3 could be null, and their lengths is not
>known.
>
>Just wondering, if there is an easy way to parse the whole string and read
>out string1, string2 and string3 into 3 strings?

What environment? ATL's string class can do this.

C:\tmp>type x.cpp
#include <stdio.h>
#include <atlstr.h>

int main()
{
CAtlString s = "<string1><string2><string3>";

int iStart = 0;
for(
CAtlString s1 = s.Tokenize("<>",iStart);
iStart >= 0;
s1 = s.Tokenize("<>",iStart)
)
{
printf( "%s\n", s1 );
}

return 0;
}

C:\tmp>cl x.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for
80x86
Copyright (C) Microsoft Corporation. All rights reserved.

x.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

/out:x.exe
x.obj

C:\tmp>.\x
string1
string2
string3

C:\tmp>


Although, now that I think about it, if one of the strings is null, it will
just skip it. If you need to know about them, you could tokenize on ">"
alone, and just delete the first character of each string.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Re: Easy way to read out formated string ? by Polaris

Polaris
Thu Jun 08 13:56:58 CDT 2006

Very interesting to know... Thanks!
Polaris

"Tim Roberts" <timr@probo.com> wrote in message
news:65if8213gcoj9t5pflqa5af0ke0kg5dkeo@4ax.com...
> "Polaris" <etpolaris@hotmail.com> wrote:
>>
>>I have a string which will always be in the format below:
>>"<string1><string2><string3>"
>>
>>Any of string1, string2 and string3 could be null, and their lengths is
>>not
>>known.
>>
>>Just wondering, if there is an easy way to parse the whole string and read
>>out string1, string2 and string3 into 3 strings?
>
> What environment? ATL's string class can do this.
>
> C:\tmp>type x.cpp
> #include <stdio.h>
> #include <atlstr.h>
>
> int main()
> {
> CAtlString s = "<string1><string2><string3>";
>
> int iStart = 0;
> for(
> CAtlString s1 = s.Tokenize("<>",iStart);
> iStart >= 0;
> s1 = s.Tokenize("<>",iStart)
> )
> {
> printf( "%s\n", s1 );
> }
>
> return 0;
> }
>
> C:\tmp>cl x.cpp
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for
> 80x86
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> x.cpp
> Microsoft (R) Incremental Linker Version 8.00.50727.42
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> /out:x.exe
> x.obj
>
> C:\tmp>.\x
> string1
> string2
> string3
>
> C:\tmp>
>
>
> Although, now that I think about it, if one of the strings is null, it
> will
> just skip it. If you need to know about them, you could tokenize on ">"
> alone, and just delete the first character of each string.
> --
> - Tim Roberts, timr@probo.com
> Providenza & Boekelheide, Inc.