-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConversorString.cpp
More file actions
61 lines (52 loc) · 1.51 KB
/
ConversorString.cpp
File metadata and controls
61 lines (52 loc) · 1.51 KB
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
57
58
59
60
61
/**
Some functions involving strings. Added as 'mandatory' utility and to avoid rewritting again and again.
This is an adapted version of part the code used for analysis in Romero & Ascasibar 2017.
Mario Romero Spring 2015
**/
#ifndef CONVERSOR_STRING_CPP
#define CONVERSOR_STRING_CPP
#include <sstream> //Only used here
//using namespace std;
string tostring(int a){
//Conversión entero->string.
stringstream conv;
conv<<a;
return conv.str();
}
string tostring(r_number a){
//Conversión real->string.
stringstream conv;
conv<<a;
return conv.str();
}
r_number todouble(string A){
//Conversión string->real
r_number n;
stringstream conv;
conv<<A;
conv>>n;
return n;
}
r_number todouble(char *A[]){
//Conversión string->real
r_number n;
stringstream conv;
conv<<A;
conv>>n;
return n;
}
bool identify(string word,string phrase){
//Busca a ver si existe una palabra en un string
if(phrase.find(word) != string::npos){ //Esta la palabra en la frase.
return true;}
return false;
}
string extract(string phrase, string start, string end){
//Extrae un string entre start (SIN CONTARLO!) y end
size_t startpos = phrase.find(start) + start.length(); //el problema esq te dara la posición incluyendo el string "start", por lo que hay que añadir la suma que se indica
size_t endpos = phrase.find(end);
//size_t length = abs(endpos-startpos); //El valor absoluto esta en el caso de que hayamos puesto las cosas al revés
size_t length = (endpos-startpos);
return phrase.substr(startpos,length);
}
#endif