simple AnsiString question

This is a discussion on simple AnsiString question within the C++ Programming forums, part of the General Programming Boards category; is there a quick way of taking out the first few letters of an ansistring? i.e. String astring = abcdef; ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    20

    simple AnsiString question

    is there a quick way of taking out the first few letters of an ansistring? i.e.
    String astring = abcdef;
    temp = astring[1 to 3];

    temp stores only abc

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    string substr (size_type pos, size_type n);
    Returns a substring of the current string, starting at position pos and of length n:

    string str18 = "abcdefghi"
    string str19 = str18.substr (6,2);
    cout << str19 << endl; // "gh"
    Might want to bookmark this page.. it's highly useful for documentation with the most popular STL classes.

    http://www.msoe.edu/eecs/ce/courseinfo/stl/
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  2. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  3. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 05:58 PM

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