To process an illegal character in the input box, convert the input illegal characters into legitimate characters.

xiaoxiao2021-03-06  109

(Original) Repost Please indicate the source

/ **

* Translate "/" in the input string to "//"

* Translate single quotes "'" to double quotes "' '"

* Return Type: string

* /

Public static string escapesqltags (string infut) {

IF (Input! = null) {

// infut = replacestring (Input, "//", "

");

INPUT = ReplaceString (Input, "/ '", "/' / '");

}

Return INPUT;

}

/ **

* "<" ">" "&" "" "" "" "" "" "" "" "" "" "" "" "

* Translate into HTML display escape characters

* Return Type: string

* /

Public Static Final String EscapeHtmltags (String in) {

IF (in == NULL) {

Return NULL;

}

CHAR CH;

INT i = 0;

INT LAST = 0;

CHAR [] INPUT = in.tochararray ();

INT LEN = INPUT.LENGTH;

StringBuffer out = new stringbuffer ((int));

For (; i

CH = INPUT [I];

IF (ch> '>') {

CONTINUE;

} else IF (CH == '<') {

IF (i> last) {

OUT.APPEND (Input, Last, I - Last);

}

Last = i 1;

OUT.APPEND (LT_Encode);

} else if (ch == '>') {

IF (i> last) {

OUT.APPEND (Input, Last, I - Last);

}

Last = i 1;

Out.append (gt_encode);

}

}

IF (Last == 0) {

Return IN;

}

IF (i> last) {

OUT.APPEND (Input, Last, I - Last);

}

Return out.toString ();

}

/ **

* Replace all OldStrings in Maistring into newstring

* Return Type: string

* /

Public Static String ReplaceString

String mainstring,

String OldString,

String newstring) {

IF (mainstring == null) {

Return NULL;

}

IF (oldString == null || oldstring.Length () == 0) {

Return mainstring;

}

IF (newstring == null) {

Newstring = "";

}

INT i = mainstring.lastIndexof (OldString);

IF (i <0) Return Mainstring;

Stringbuffer mainsb = new stringbuffer; mAinstring;

While (i> = 0) {

Mainsb.replace (i, i ildstring.length (), newstring;

I = mainstring.lastindexof (Oldstring, I - 1);

}

Return MAINSB.TOSTRING ();

}

转载请注明原文地址:https://www.9cbs.com/read-98796.html

New Post(0)