Skip to content
Snippets Groups Projects
Commit b6af40e5 authored by Andreas Blakli's avatar Andreas Blakli
Browse files

La til:

To nye filer: hjelpeFunksjoner.cpp og hjelpeFunksjoner.h med klassen HjelpeFunksjoner.
rensStreng() func.
sjekkForUlovligTegn() func.
erBokstav() func.
parent b9c6076d
No related branches found
No related tags found
No related merge requests found
#include "hjelpeFunksjoner.h"
using namespace std;
string HjelpeFunksjoner::rensStreng(const string str) {
if (sjekkForUlovligTegn(str)) {
string rensetStreng;
regex re("[^ÆØÅæøåa-zA-Z0-9]");
rensetStreng = regex_replace(str, re, "");
return rensetStreng;
}
return str;
}
bool HjelpeFunksjoner::sjekkForUlovligTegn(const string str) {
regex re("[^ÆØÅæøåa-zA-Z0-9 ]");
if (regex_search(str, re)) {
cout << "\nUlovlig karakter(er) funnet! Venligst bare bruk: A-z 0-9"
<< '\n';
return true;
}
return false;
}
bool HjelpeFunksjoner::erBokstav(const string str) {
// auto x = find_if(str.begin(), str.end(),
// []() { return isalpha('s') > 0; });
if (count(str.begin(), str.end(), isalpha(str.back()))) return true;
return false;
}
\ No newline at end of file
#ifndef __HJELPEFUNKSJONER_H
#define __HJELPEFUNKSJONER_H
#include <iostream>
#include <string>
#include <algorithm>
#include <regex>
#include <cctype>
class HjelpeFunksjoner {
public:
std::string rensStreng(std::string str);
bool sjekkForUlovligTegn(std::string str);
bool erBokstav(std::string str);
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment