string padding and replacement functions

This is a discussion on string padding and replacement functions within the Tech Board forums, part of the Community Boards category; Hello everyone, I want to steal some Linux string manipulation functions (replacement and padding) in my C/C++ program to process ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    string padding and replacement functions

    Hello everyone,


    I want to steal some Linux string manipulation functions (replacement and padding) in my C/C++ program to process a couple of large files to save my time. :-)

    I want to use,

    1. String padding, for example, padding a sign ':' to each end of line;
    2. String replacement, for example, replace "enter" with "exit";

    All the files I am working on are text files (ASCII). I am wondering what Linux command(s) should I use? Could anyone show me an example please?


    thanks in advance,
    George

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    1) You shouldn't use any Linux commands (as in "the stuff you use from shell scripts") from within a C or C++ program. Doing so means spawning a shell in which to execute the command, which is very, very slow.
    2) There's no such thing as C/C++.
    3) Search for string manipulation libraries. For C++, you can use Boost.String_Algo.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    All your recent tech board questions suggest you should use perl, rather than some chaotic mix of shell script, sed, awk and bits of compiled C code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Quote Originally Posted by CornedBee
    1) You shouldn't use any Linux commands (as in "the stuff you use from shell scripts") from within a C or C++ program. Doing so means spawning a shell in which to execute the command, which is very, very slow.
    2) There's no such thing as C/C++.
    3) Search for string manipulation libraries. For C++, you can use Boost.String_Algo.
    thank you for your advice, CornedBee!


    regards,
    George

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Quote Originally Posted by Salem
    All your recent tech board questions suggest you should use perl, rather than some chaotic mix of shell script, sed, awk and bits of compiled C code.

    Thank you for your advice, Salem!


    regards,
    George

Popular pages Recent additions subscribe to a feed

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