Last active
July 14, 2021 06:40
-
-
Save baskurthalit/f6dfe167d8ca4e8b0826b9a1dc70b860 to your computer and use it in GitHub Desktop.
C++ | String Bölme-Parçalama - String Splitting - bseyha.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* www.bseyha.com/string-bolme-parcalama-c-cpp/ */ | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
vector<string> split(const char *str , char k = ' '){ | |
vector<string> sonuc; //Geri döndürmek için | |
while(*str++!=0 && *str){ | |
const char *baslangic = str; | |
while(*str != k && *str){ | |
str++; | |
} | |
sonuc.push_back(string(baslangic,str)); | |
//string(first,last) parametlerine göre değer alır, bu aralıktakileri (ilk değer dahil ve son değer dahil olmamak)bir string yapar. | |
//push_back ise vectör listesi(sonuc olarak belirlediğimiz), sonuna oluşan (string(baslangic,str) ile) string'i atar. | |
} | |
return sonuc; | |
}//Fonskiyon bitimi | |
int main(){ | |
const char mystring[] = " bseyha.com bilgi paylaşınca güzel"; | |
vector<string> result = split(mystring); | |
cout<< result[1]; | |
cout<< result[1]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment