“CPP String Slice” Kod odpowiedzi

SPLICE STRING w C

string str1 = "Apples are red";
string str2 = str1.substr(11, 3); // "red"
string str3 = str1.substr(0, 6); // "Apples"
Anxious Alligator

CPP String Slice

//Time complexity: O(n)

//Auxiliary Space: O(n)

#include <string.h>
#include <iostream>
using namespace std;
 
int main()
{
    // Take any string
    string s1 = "Geeks";
 
    // Copy three characters of s1 (starting
    // from position 1)
    string r = s1.substr(3, 2);
 
 	// Copy substring after pos
	string sub = s.substr(pos + 1);
	
	// Copy substring before pos
    string sub = s.substr(0 , pos);
    
    // prints the result
    cout << "String is: " << r;
 
    return 0;
}
Fancy Flatworm

Odpowiedzi podobne do “CPP String Slice”

Pytania podobne do “CPP String Slice”

Więcej pokrewnych odpowiedzi na “CPP String Slice” w C++

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu