Código fuente de 'Operaciones con cadenas 2.asp'
<html>
<head>
<title>Operaciones con cadenas 2 - Códigos asp, programacion asp, descargas asp, rutinas asp</title>
</head>
<p align="center"><b><font size="3">Operaciones con cadenas 2</font></b>
<body style="font-family: Arial; font-size: 9pt">
</p>
<br><br><b>Aquí tienes seis funciones para operar con cadenas (ver
implementación en código
fuente):<br>
</b>
Descripción de las funciones:
<br><u>Replace_Bad_Words</u> - Una función que permite eliminar palabras
malsonantes.
<br><u>Rep_Chars</u> - Una función que permite eliminar caracteres no deseados (html,
especiales, etc).<br><u>Fix_Chars</u> - Coge los caracteres de la función
anterior para que puedan ser mostrados en HTML.<br><u>Sentence_Continue</u> - Formatea
una cadena demasiado larga para que tenga cierto tamaño, añadiendo "..." al
final.
<br><u>Count_Words</u> - Cuenta el número de palabras en una cadena.<br><u>Make_Word_Wrap</u> -
Lo que hace es cortar las palabras muy largas insertando un espacio.
<br>
<%
'Copyright 2003 Squiver, Inc.®
'Made By Adam Smith on Aug 1, 2003 for squiver.com
'License: You are free to use these functions as you please.
'Function Descriptions:
'*Replace_Bad_Words - A replace function for removing cursing from strings.
'*Rep_Chars - A replace function for removing unwanted characters from strings(html, special, reserved) for database storage.
'*Fix_Chars - A replace function for fixing characters made by Rep_Chars. Fixes characters for html display.
'*Sentence_Continue - Formats a string to a certain size if too long, then adds a ... to the end of it.
'*Count_Words - Counts the number of words in a string.
'*Make_Word_Wrap - Wraps the number of allowed characters, by adding a space to break up excessively long words.
Function Replace_Bad_Words(Data)
'Check to see if data has something---
If Data = "" Then Exit Function
'-------------------------------------
'Dirt Words----------------------
Bad_Word = Array("ass", "bitch", "biatch", "blowjob", "bukkake", "bullshit", "cunt", "cum", "dicked", "dickhead" _
& "dickweed", "dildo", "fuck", "gangbang", "goddamnit", "handjob", "jackoff", "motherfucker", "motherfucking" _
& "pissed", "pisses", "porno", "pussy", "pussified", "shit", "titties", "twat")
'--------------------------------
'Replace Bad Words-----------------
For Bad = 0 To UBound(Bad_Word)
Data = Replace(Data, Bad_Word(Bad), String(Len(Bad_Word(Bad)), "*"), , , vbTextCompare)
Next
'----------------------------------
'Return Data---------------
Replace_Bad_Words = Data
'--------------------------
End Function
Function Rep_Chars(Data)
'Replace caracters to allow in database, one to one ratio---
Data = Replace(Data, Chr(60), Chr(251))
Data = Replace(Data, Chr(62), Chr(252))
Data = Replace(Data, Chr(34), Chr(253))
Data = Replace(Data, Chr(39), Chr(254))
Data = Replace(Data, Chr(13), Chr(255))
'-----------------------------------------------------------
'Return Data------
Rep_Chars = Data
'-----------------
End Function
Function Fix_Chars(Data)
'Fix Characters from database to display in html-----
Data = Replace(Data, Chr(251), "<")
Data = Replace(Data, Chr(252), ">")
Data = Replace(Data, Chr(253), """)
Data = Replace(Data, Chr(254), "'")
Data = Replace(Data, Chr(255), "<br>")
'----------------------------------------------------
'Return Data------
Fix_Chars = Data
'-----------------
End Function
Function Sentence_Continue(Data, chrlength)
'Return number of allowed characters------------
If Len(Data) > chrlength Then
Sentence_Continue = Mid(Data, 1, chrlength) & "..."
Else
Sentence_Continue = Data
End If
'-----------------------------------------------
End Function
Function Count_Words(Data)
'Count the number of words--------
Words = Split(Data, " ")
Count_Words = Int(UBound(Words) + 1)
'---------------------------------
End Function
Function Make_Word_Wrap(Data_String, Word_Size_Allowed)
'Declare Starting Variables--------------
Counter = 0
Fixed_Word = ""
'----------------------------------------
'Check to see if Data String is empty--------
If Data_String = "" Then Exit Function
'--------------------------------------------
'Check to see if Data_String is smaller than word size-----------
If Len(Data_String) < Word_Size_Allowed Then
Make_Word_Wrap = Data_String
Exit Function
End If
'----------------------------------------------------------------
'Split data into array for size checking---------------
DataOf = Split(Data_String, " ")
'------------------------------------------------------
For Breakdown = LBound(DataOf) To UBound(DataOf)
'Check to see how long word is-------------------
If Len(DataOf(Breakdown)) > Word_Size_Allowed Then
'Start checking individual word sizes and replace where too long----
For breakword = 1 To Len(DataOf(Breakdown))
Counter = Counter + 1
'Replace characters that are too long with spaces-------------
If Counter > Word_Size_Allowed Then
Fixed_Word = Fixed_Word & " " & Mid(DataOf(Breakdown), breakword, 1)
Counter = 1
Else
Fixed_Word = Fixed_Word & Mid(DataOf(Breakdown), breakword, 1)
End If
'-------------------------------------------------------------
Next
'-------------------------------------------------------------------
'Set new values and reset word-----------------
DataOf(Breakdown) = Fixed_Word
Fixed_Word = ""
'----------------------------------------------
End If
'------------------------------------------------
Next
'Rebuild Data String----------------------
For Rebuild = LBound(DataOf) To UBound(DataOf)
New_String = New_String & DataOf(Rebuild) & " "
Next
New_String = Mid(New_String, 1, Len(New_String) - 1)
'-----------------------------------------
Make_Word_Wrap = New_String
End Function
%>
</body>
</html>