How should I go about finding a string within two chars in c++? -


hello been trying find way of finding string of characters within 2 characters. how should go doing in c++?

sdfgkjr$joeisawesome$sdfeids -> joeisawesome 

edit: other answer looking if string exist within string. i'm looking string within 2 characters , outputting sting within 2 chars. thank looking pox.

okay, when 2 characters, i'm assuming referring delimiters. in case have use string.find() find position of delimiters. after finding positions of delimiters, can can use string.substr(index1,index2-index1) return substring.

example:

#include <iostream> #include <string>  int main() {     std::size_t index1,index2;     std::string mystring = "sdfgkjr$joeisawesome$sdfeids";     std::string sub= "";     index1 = mystring.find('$');      //string::npos -1 if unaware      if(index1!=std::string::npos&& index1<mystring.length()-1)         index2=mystring.find('$',index1+1);     if(index2!=std::string::npos)     {         sub = mystring.substr(index1+1,index2-index1);     }        std::cout<<sub; //outputs joeisawesome } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -