CitarDado una cadena de caracteres separar los numeros de las letras, descartando espacios y cualquier otro simbolo.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body bgcolor="121212" text="#FFFFFF">
<center>
<form action="" method="POST">
<textarea name="texto" id="texto" cols="40" rows="7"></textarea><br />
<input type="submit" value="Elimiar Espacios" />
</form>
<?php
@$texto = $_POST['texto'];
for($i=0; $i<strlen(@$texto); $i++)
{
@$info[$i] = @$texto[$i];
if(ord($info[$i])!= 32)
{
@$sinespacio .= @$info[$i];
}
}
echo '<input type="text" name="numero" value="'.@$sinespacio.'" size="35"/><br />';
?>
</center>
</body>
</html>
<?php
function separar($texto) {
$texto = str_replace(array("\n","\r"," "),"",$texto);
$chars = array("letras"=>"","num"=>"");
for($i=0;$i<strlen($texto);$i++) {
if((int)$texto{$i}) $chars["num"].=$texto{$i}; else $chars["letras"].=htmlentities($texto{$i});
}
return json_encode($chars);
}
if(isset($_GET["txt"])) {
echo separar($_GET["txt"]);
exit;
}
?>
<html>
<head>
<title>Reto programación de Expermicid</title>
<style type="text/css">
* { font-family: Verdana; font-size: 12px; }
body { text-align:center; background:#D1D1D1; }
textarea, input { width:400px; height: 100px; }
input { font-size:20px; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script>
function split() {
$.getJSON("<?=htmlentities($_SERVER["PHP_SELF"]);?>", { txt: $("#texto").val() }, function(response) {
$("#letras").val(response.letras);
$("#numeros").val(response.num);
});
}
</script>
</head>
<body>
<h1>Separador de numeros</h1>
<form method="POST" onSubmit="split();return false;">
Texto a separar:<br>
<textarea id="texto"></textarea>
<br>
<input type="submit" id="send" value="Separar" /><br>
Letras: <br><input type="text" id="letras" disabled /><br>
Números: <br><input type="text" id="numeros" disabled /><br>
</form>
</body>
</html>
#!/usr/bin/python
# Resolucion reto underc0de.org
# Separar numeros de letras y viceversa :-/
# By Neutron =)
import re
print "Reto Programacion underc0de.org\n"
entrada = raw_input("Introduzca una cadena con letras y numeros: ")
letras = ""
numeros = ""
for i in entrada:
if re.match("\d",i):
numeros += i
if re.match("[a-zA-Z]",i):
letras += i
print "\nLos numeros son: ",numeros
print "\nLas letras son: ",letras
~
~
~