Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

remove whitespace in cpp

string removeWhiteSpaces(string line) {
	string s = "";
	int space = 0;
	while (true) {
		if (line[space] == ' ')
			space++;
		else break;
	}
	for (int x = space; x < line.length(); x++)
		s += line[x];

	space = s.length() - 1;
	while (true) {
		if (s[space] == ' ') {
			space--;
		}
		else 
			break;
	}
	for (int x = 0; x <= space; x++)
		s[x] = s[x];
	s[space + 1] = '';
	return s;
}

input  = "           String            "
ouput = "String"
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #remove #whitespace #cpp
ADD COMMENT
Topic
Name
1+6 =