Thread: Best way to find, extract, replace, etc in char strings?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    161

    Best way to find, extract, replace, etc in char strings?

    I could never figure out an easy way to handle strings in C. I need to find and extract part of a string up to the last occurrence of a particular character, and probably find/replace. I assume everything I need is in string.h, but I'm not having an easy time finding examples of specific tasks. For example. strrchar() returns a pointer. How am I supposed to use that pointer to extract everything up to that character? strncpy() expects to be told the number of chars to extract, not a pointer to the last one.

    Also, is there a simple way to trim BS characters from the start and end of a strings? VB6 had a Trim() function that filtered out whitespace and other special chars(\t,\n, etc) from the beginning and end of a string.

    I'm currently working with my char strings declared "char stringname[maxlength];" I'm curious as to the difference between this and cString/LPSTR. I don't think I've ever seen a cString used in an example without having to malloc() the damn thing. I don't want to do that, since you always have to free the memory later. Or is cString like the MFC solution to Char*? I want to stay away from MFC.
    Last edited by Viper187; 06-09-2008 at 12:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. help with strings
    By webbizdesign in forum C Programming
    Replies: 5
    Last Post: 11-13-2003, 08:20 PM
  3. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  4. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM