Funcion para convertir entre ASCII y Caracteres en ASP
Esta funcion puede servir para por ejemplo cuando queremos hacer una validacion de usuarios respetanto mayusculas y minusculas (cosa que no hace ASP). Tenemos la opcion de convertir los caracteres por su valor en ASCII y viceversa, la funcion es:
Function StringToAscii(str)
Dim result, x
StringToAscii = ""
If Len(str)=0 Then Exit Function
If Len(str)=1 Then
result = Asc(Mid(str, 1, 1))
StringToAscii = Left("000", 3-Len(CStr(result))) & CStr(result)
Exit Function
End If
result = ""
For x=1 To Len(str)
result = result & StringToAscii(Mid(str, x, 1))
Next
StringToAscii = result
End Function
Function AsciiToString(str)
Dim result, x
AsciiToString = ""
If Len(str)<3 Then Exit Function
If Len(str)=3 Then
AsciiToString = Chr(CInt(str))
Exit Function
End If
result = ""
For x=1 To Len(str) Step 3
result = result & AsciiToString(Mid(str, x, 3))
Next
AsciiToString = result
End Function
'usage
Dim myString, strASCII
myString = "hello world"
strASCII = StringToAscii(myString)
Response.Write("original string: " & myString & "
")
Response.Write("ASCII: " & strASCII & "
")
Response.Write("back to string: " & AsciiToString(strASCII) & "
")
Etiquetas: asp funcion caracter ascii

0 comentarios:
Publicar un comentario en la entrada
Enlaces a esta entrada:
Crear un enlace
<< Página principal