Buscar..


Observaciones

Impulsar la documención en los algroritmos de cuerdas

boost :: split ()

#include <iostream>
#include <vector>
#include <string>
#include <boost/algorithm/string.hpp>

using namespace std;

int main()
{

    // String to split

    string str = "You're supposed to see this!|NOT THIS!!!!!!";

    // Line container

    vector<string> lines;

    // Splits string

    boost::split(lines, str, boost::is_any_of("|"), boost::token_compress_on);

    // Outputs 1 half of the split string

    cout << lines.at(0).c_str() << endl;

    // Waits for input before program exits

    cin.get();

    return 0;
}

El siguiente es el programa en psuedocode :

Declarar cadena str y la puso a "Se supone que ver esto |! NO ESTA !!!!!!" .

Declarar líneas vectoriales de tipo cadena.

Dividir cadena str en líneas vectoriales si regex "|" es encontrado.

Imprimir objeto en el índice 0 en líneas.

Obtener entrada.

Reemplazar Algrorithms

boost :: replace_all ():

#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>

using namespace std;

int main()
{

    // String to replace characters in

    string str = "Darn you, Darn you to the 5th power!!!";

    // Replace "Darn" with "*CENSORED*"

    boost::replace_all(str, "Darn", "*CENSORED*");

    // Print str

    cout << str.c_str() << endl;

    // Waits for program to exit

    cin.get();

    return 0;
}

boost :: replace_first ():

#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>

using namespace std;

int main()
{

    // String to replace characters in

    string str = "Darn you, Darn you to the 5th power!!!";

    // Replace the first instance of "Darn" with "*CENSORED*"

    boost::replace_first(str, "Darn", "*CENSORED*");

    // Print str

    cout << str.c_str() << endl;

    // Waits for program to exit

    cin.get();

    return 0;
}

boost_replace_last ():

#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>

using namespace std;

int main()
{

    // String to replace characters in

    string str = "Darn you, Darn you to the 5th power!!!";

    // Replace the last instance of "Darn" with "*CENSORED*"

    boost::replace_last(str, "Darn", "*CENSORED*");

    // Print str

    cout << str.c_str() << endl;

    // Waits for program to exit

   cin.get();

   return 0;
}

Métodos de conversión de casos

to_upper ():

#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>

using namespace std;

int main()
{

    // String to convert characters to uppercase

    string str = "ThIS iS SUpPoSEd tO Be UpPeR CAsE.";

    // Convert characters in str to upper case

    boost::to_upper(str);

    // Print str

    cout << str.c_str() << endl;

    // Waits for program to exit

    cin.get();

    return 0;
}

reducir():

#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>

using namespace std;

int main()
{

    // String to convert characters to lowercase

    string str = "ThIS iS SUpPoSEd tO Be LoWer CAsE.";

    // Convert characters in str to lower case

    boost::to_lower(str);

    // Print str

    cout << str.c_str() << endl;

    // Waits for program to exit

    cin.get();

    return 0;
}


Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow