美文网首页JavaBean专题
检查字符串是否以指定字符串开头

检查字符串是否以指定字符串开头

作者: 神坛下的我 | 来源:发表于2018-08-18 18:38 被阅读0次

StringUtil7.java

public class StringUtil7 {
    private String startStr;//指定开头的字符串
    private String str;//被判断的字符串
    private boolean check;
    public String getStartStr() {
        return startStr;
    }
    public void setStartStr(String startStr) {
        this.startStr = startStr;
    }
    public String getStr() {
        return str;
    }
    public void setStr(String str) {
        this.str = str;
    }
    public boolean isCheck() {
        /*该方法判断字符串是否以指定字符开头*/
        return str.startsWith(startStr);
    }
    
}

index.jsp

<body>
    <form action="result.jsp" method="post">
        <table>
            <tr>
                <td align="right">请输入字符串:</td>
                <td><input type="text" name="str" size="40"/></td>
            </tr>
            <tr>
                <td align="right">请输入开头的字符串:</td>
                <td><input type="text" name="startStr"/></td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="submit" value="验证"/></td>
            </tr>
        </table>
    </form>
</body>

result.jsp

<body>
    <%
        request.setCharacterEncoding("utf-8");
        String str= request.getParameter("str");
        String startStr= request.getParameter("startStr");
    %>
    <jsp:useBean id="strBean" class="com.count.StringUtil7"></jsp:useBean>
    <jsp:setProperty property="str" name="strBean" value="<%=str %>"/>
    <jsp:setProperty property="startStr" name="strBean" value="<%=startStr %>"/>
    
    <table>
        <tr>
            <td>过滤之前的字符串:</td>
            <td align="left">
                <jsp:getProperty property="str" name="strBean"/>
            </td>
        </tr>
        <tr>
            <td>开头的字符串:</td>
            <td align="center">
                <jsp:getProperty property="startStr" name="strBean"/>
            </td>
        </tr>
        <tr>
            <td>验证结果:</td>
            <td align="right">
                <jsp:getProperty property="check" name="strBean"/>
            </td>
        </tr>
    </table>
</body>
1.PNG 2.PNG 3.PNG

相关文章

  • 字符串相关方法

    startsWith():字符串是否以指定的内容开头 语法: 解释:判断一个字符串是否以指定的子字符串开头。如果是...

  • 字符串操作2

    startswith()方法判断字符串是否以指定的字符串开头,返回布尔值 endswith() 判断字符串是否以指...

  • 2018-07-09-Python3 startswith()方

    startswith() 方法用于检查字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False...

  • 检查字符串是否以指定字符串开头

    StringUtil7.java index.jsp result.jsp

  • startsWith()和endsWith() 的使用

    定义和用法startsWith() 方法用于检测字符串是否以指定的子字符串开始。如果是以指定的子字符串开头返回 t...

  • Design & Coed 5:检查字符串结尾

    检查字符串结尾 Confirm the Ending 判断一个字符串(str)是否以指定的字符串(target)结...

  • NSString

    :表示字符串是否以指定的字符串(str)结尾,返回bool值 :表示字符串是否以指定的字符串(str)开始,返回b...

  • 字符串扩展

    includes(str) : 判断是否包含指定的字符串 startsWith(str) : 判断是否以指定字符串...

  • 每日python—— 匹配字符串开头或结尾

    在实际应用中,经常会遇到检查字符串是否以指定字符开头或结尾的情况,最常见的就是检查文件后缀名了,python中提供...

  • Confirm the Ending

    检查字符串结尾 判断一个字符串(str)是否以指定的字符串(target)结尾。 如果是,返回true;如果不是,...

网友评论

    本文标题:检查字符串是否以指定字符串开头

    本文链接:https://www.haomeiwen.com/subject/einfiftx.html