怎么把HTML格式的转成字符串

怎么把HTML格式的转成字符串,第1张

一个String显示在网页上,不会安置原来的格式显示,比如说,回车符在网页上就显示成了一个空格,下面这个方法可以。把HTML格式的转成字符串

public static String toHTMLString(String in) {

StringBuffer out = new StringBuffer()

for (int i = 0in != null &&i <in.length()i++) {

char c = in.charAt(i)

if (c == '\'')

out.append("'")

else if (c == '\"')

out.append(""")

else if (c == '<')

out.append("<")

else if (c == '>')

out.append(">")

else if (c == '&')

out.append("&")

else if (c == ' ')

out.append(" ")

else if (c == '\n')

out.append("<br/>")

else

out.append(c)

}

return out.toString()

}

格式化字符串的意思是使用Format函数将指定的字符串转换为想要的输出格式。

Format函数返回Variant(String),其中含有一个表达式,它是根据格式表达式中的指令来格式化的。

如果要格式化一个没有本地化的数值字符串,应该使用一个用户自定义的数值格式,以保证得到需要的外观。

扩展资料

Format 函数做格式化输出的不同用法。对于日期分隔号(/),时间分隔号(:),以及 AM/ PM 等文本而言,其真正的显示格式会因计算机上的国际标准不同而有所差异。

在开发阶段,日期与时间是以短日期的格式,配合代码的国际标准来显示的。而在运行时,短日期则是根据系统的国际标准而定,而系统的国际标准和代码的国际标准可能并不相同。

格式指令具有以下的形式: "%" [index ":"] ["-"] [width] ["." prec] type

是以"%"开始,而以type结束,type表示一个具体的类型。中间是用来格式化type类型的指令字符,是可选的。

参考资料来源:百度百科-Format函数

content-type是内容类型,用于定义网络文件的类型和网页的编码,决定文件接收方将以什么形式、什么编码读取这个文件。

用法示例:<meta content="text/htmlcharset=gb2312" http-equiv="Content-Type"/>

描述内容类型的字符串。该字符串通常被格式化为类型/子类型,其中类型是常规内容范畴而子类为特定内容类型。

扩展资料

content-type文件内容对照:

".*"="application/octet-stream"

".001"="application/x-001"

".301"="application/x-301"

".323"="text/h323"

".906"="application/x-906"

".907"="drawing/907"

".a11"="application/x-a11"

".acp"="audio/x-mei-aac"

".ai"="application/postscript"

".aif"="audio/aiff"

".aifc"="audio/aiff"

".aiff"="audio/aiff"

".anv"="application/x-anv"

".asa"="text/asa"

".asf"="video/x-ms-asf"

".asp"="text/asp"

".asx"="video/x-ms-asf"

".au"="audio/basic"

".avi"="video/avi"

".awf"="application/vnd.adobe.workflow"

".biz"="text/xml"

".bmp"="application/x-bmp"

".bot"="application/x-bot"

".c4t"="application/x-c4t"

".c90"="application/x-c90"

".cal"="application/x-cals"

".cat"="application/s-pki.seccat"

".cdf"="application/x-netcdf"

".cdr"="application/x-cdr"

".cel"="application/x-cel"

".cer"="application/x-x509-ca-cert"

".cg4"="application/x-g4"

".cgm"="application/x-cgm"

参考资料来源:百度百科-ContentType


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7081241.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-01
下一篇 2023-04-01

发表评论

登录后才能评论

评论列表(0条)

保存