DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2005
    Posts
    58

    Question how to split the string in to components?

    I have wchar_t (string) 11.12.13.122
    now start is pointer of type wchar_t which is pointing to this string.
    i want to separate each component of string.
    here"." is delimiter
    here is code
    wchar_t *hr = wstrtok(start,L'.');//hr is now pointing to 11

    wchar_t *min = wstrtok(null,L'.');//min is now pointing to 12

    wchar_t *sec = wstrtok(null,L'.');//sec is now pointing to 13
    How should i get pointer to 122 as now i dont have delimiter
    will the following work?
    wchar_t *milisec = wstrtok(null,L'/0');

    About wstrtok:

    The wstrtok subroutine returns a pointer to an occurrence of a text token in the string pointed to by the XString1 parameter. The XString2 parameter specifies a set of code points as token delimiters. If the XString1 parameter is anything other than null, then the wstrtok subroutine reads the string pointed to by the XString1 parameter until it finds one of the delimiter code points specified by the XString2 parameter. It then stores a wchar_t null into the wchar_t string, replacing the delimiter code point, and returns a pointer to the first wchar_t of the text token. The wstrtok subroutine keeps track of its position in the wchar_t string so that subsequent calls with a null XString1 parameter step through the wchar_t string. The delimiters specified by the XString2 parameter can be changed for subsequent calls to wstrtok. When no tokens remain in the wchar_t string pointed to by the XString1 parameter, the wstrtok subroutine returns a null pointer.

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    Your original wchar_t string of 11.12.13.122 should have a L'0' terminator at the end (after 122) so wstrtok should work. If there's no null terminator at the end, add it to the original string before you start parsing it. BTW, if your original string always contains cc.cc.cc.ccc where c represents a digit, you don't really need strtok. Simply read 2,2,2, and 3 characters from the string (and remember to skip the delimiter each time).
    Danny Kalev

  3. #3
    Join Date
    May 2005
    Posts
    58
    Thanx a lot ........
    indeed that was of great help.i will follow ur suggestion

    thanx again
    swapnil.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links