함수 filter alphabet()


1 C[ | ]

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

char* filter_alphabet(char* str) {
	char *result = malloc(strlen(str)+1);
	int i = 0;
	char *p;
	for( p = str; *p != '\0'; p++ ) {
		if( isalpha(*p) ) {
			result[i] = *p;
			i++;
		}
	}
	result[i] = '\0';
	return result;
}
main() {
	char *in = "qwerty\n!@#Hello, Café!!";
	char *out = filter_alphabet( in );
	printf("%s\n", out);
}
// qwertyHelloCaf

2 PHP[ | ]

$in = "qwerty\n!@#Hello, Café!!";
$out = preg_replace("/[^a-zA-Z]/", "", $in);
var_dump($out);
# string(14) "qwertyHelloCaf"

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}