Extract a character of a String

Hi Friends

How can i extract a character of a string ?

Example:

string "SUBMISSION"
Extract only "M"

This in Perl language is --> substr("SUBMISSION", 4, 1)

How is it in C++ ?

Comments

  • : Hi Friends
    :
    : How can i extract a character of a string ?
    :
    : Example:
    :
    : string "SUBMISSION"
    : Extract only "M"
    :
    : This in Perl language is --> substr("SUBMISSION", 4, 1)
    :
    : How is it in C++ ?
    :
    "SUBMISSION"[3]

  • Hola,

    I think you wanted:

    char *string = "submission";
    char M = string[4];

    if your are using stl, std, you can use std::string
    basic_string::substr
    basic_string substr(size_type pos = 0,
    size_type n = npos) const;
    The member function returns an object whose controlled sequence is a copy of up to n elements of the controlled sequence beginning at position pos.


    --------------------------------------------------------------------------------


    : Hi Friends
    :
    : How can i extract a character of a string ?
    :
    : Example:
    :
    : string "SUBMISSION"
    : Extract only "M"
    :
    : This in Perl language is --> substr("SUBMISSION", 4, 1)
    :
    : How is it in C++ ?
    :


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories