Hi, I would like to get a better understanding with each slicing and determine how to sweep through a user defined input, as researching the internet there's so many complicated examples, to many crazy algorithms that would make your jaw drop, but I decided to simplify what I know, the code put forth isn't anything special, so I'm not sure if a binary search in ascaii is the only solution given its stored in decimal places, but that would be a nightmare to implement.
Anyways to the code, what we want is:
1 test andrew_becroft@gmail.com
Or copy it in as input, really any emails perfectly fine, but we must break the user name as we would in SQL, similar to merge and join ect, in the below code, we stop at the ampersand, but what we really want is to determine the string as input and store the name, if we wanted to store it as a text file that's a option, but not necessary as we want to separate the names for better readability.
(P,s I'm not sure if includes are even necessary so I just put them in given the preview window shows nothing.)
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <fstream>
#include <list>
#include <unordered_set>
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::endl;
using std::fstream;
using std::ofstream;
using std::size_t;
using std::unordered_set;
int main ()
{
string test = "andrew_becroft@gmail.com";
//string test;
//cin>>test;
std::size_t pos = test.find("");
std::size_t pos1 = test.find("_");
std::size_t pos2 = test.find("@");
std::string str1 = test.substr(pos,pos2);
std::string str2 = test.substr(pos2,pos1);
//str1 = test.substr(0,pos2);
//str2 = test.substr(pos2,pos1);
cout<< str1 <<" length:"<<str1.length()<<"\n";
return 0;
}
|
Does the same above but splits it, but doesn't work with user defined input because we have no idea what input we will get, that's the point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <fstream>
#include <list>
#include <unordered_set>
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::endl;
using std::fstream;
using std::ofstream;
using std::size_t;
using std::unordered_set;
int main ()
{
string test = "andrew_becroft@gmail.com";
//string test;
//cin>>test;
std::size_t pos = test.find("");
std::size_t pos1 = test.find("_");
std::size_t pos2 = test.find("@");
std::string str1 = test.substr(pos,pos2);
std::string str2 = test.substr(pos2,pos1);
//str1 = test.substr(0,pos2);
//str2 = test.substr(pos2,pos1);
cout<< str1 <<" length:"<<str1.length()<<"\n";
//cout<< str2 <<" length:"<<str2.length()<<"\n"<<endl;
char str[] = "andrew_becroft@gmail.com";
char key[] = "@";
char key2[] = "_";
char *pch;
pch = strtok(str, key);
pch = strtok(str, key2);
while(pch!= NULL)
{
cout << "\n" << pch;
pch = strtok(NULL, "");
}
return 0;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
Just exploring different solutions??? really adds nothing.
[code]
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <fstream>
#include <list>
#include <unordered_set>
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::endl;
using std::fstream;
using std::ofstream;
using std::size_t;
using std::unordered_set;
int main ()
{
string test={"andrew_becroft@gmail.com"};
string str1;
auto search_1 = test.find("b");
auto search_2 = test.find("@");
auto search_3 = test.find(".");
if((search_1)&&(search_2)&&(search_3)){
cout <<"found"<<endl;
str1 = test.erase(search_1);
str1 = test.erase(search_2);
str1 = test.erase(search_3);
//cout << str1;
//str1 = test.substr(search_1);
//str1 = test.substr(search_1,search_2);
//str1 = test.substr(search_2,search_1);
//cout <<search_1<<search_2m<<endl;
}else{
cout<<"not found"<<endl;
}
for (auto& n: str1){
cout<<n;
}
cout << endl;
}
|
Just to reiterate what I want to achieve:
1 user defined email that we cannot predict
2 sweep through the ascaii keys, or strings (what ever you want to call it)
3 index the name and output it removing the email essentially.
Any inputs also welcome if I was in the right direction or poorly of track.