text.java

来自「一个用java开发的具有搜索功能的图书管理系统」· Java 代码 · 共 59 行

JAVA
59
字号
package library;

public class Text {

	public Text(){}
	
	public static String elideText(String text,int maxLength)
	{
		if(text!=null&&text.length()>maxLength)
		{
			return text.substring(0,maxLength)+"……";
		}
		else
		{
			return text;
		}
	}
	
	public static String textToHtml(String text) 
	{
		if (text == null || text.equals(""))
		{
			return "";
		}
		text = text.replaceAll("&", "&");
		text = text.replaceAll("<", "&lt;");
		text = text.replaceAll(">", "&gt;");
		text = text.replaceAll("  ", "&nbsp;");
		text = text.replaceAll("\n", "<br>");
		text = text.replaceAll("'", "&rsquo;");
		text = text.replaceAll("\"","&quot;");
		text = text.replaceAll("\"","&quot;");
		return text;
	}
	
	public static String htmlToText(String html)
	{
		if (html == null || html.equals(""))
		{
			return "";
		}
		html = html.replaceAll( "&amp;","&");
		html = html.replaceAll( "&lt;","<");
		html = html.replaceAll( "&gt;",">");
		html = html.replaceAll( "&nbsp;","  ");
		html = html.replaceAll( "<br>","\n");
		html = html.replaceAll( "&rsquo;","'");
		html = html.replaceAll( "&quot;","\"");
		html = html.replaceAll("&quot;","\"");
		return html;
	}
	public static String getFileName(String path)
	{
		path=path.replaceAll("/","\\\\");
		int temp=path.lastIndexOf('\\');
		return path.substring(temp+1);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?