cut/token which command?

This is a discussion on cut/token which command? within the C++ Programming forums, part of the General Programming Boards category; Hello I have a char variable with lets say: It's:a:test Now I want to cut this char into parts by ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    cut/token which command?

    Hello

    I have a char variable with lets say: It's:a:test

    Now I want to cut this char into parts by specifying the character where to cut, in this case it is the ":".

    Thx for help

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    You mean you have a string "a:text" and you want to search it for a specific character? if you use std::string then use its find() method. If the string is char* then use strchr() function. Another way is to create a loop that checks each character of the string.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    In C there's a function for tokenizing strings, called strtok, but it has got some shortcomings.
    http://www.cppreference.com/stdstring/strtok.html

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    thx the strchr() function does the work

  5. #5
    xhi
    xhi is offline
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    Quote Originally Posted by joni
    In C there's a function for tokenizing strings, called strtok, but it has got some shortcomings.
    http://www.cppreference.com/stdstring/strtok.html
    yes i have always got a kick out of the man page for strtok

    quote-- "Never use these functions."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 10:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  4. Ping problem
    By bladerunner627 in forum C++ Programming
    Replies: 12
    Last Post: 02-02-2005, 12:54 PM
  5. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21