模糊判断字符串存在与否

《个人作品》:新人学习

模糊判断字符串存在与否

 1         /// <summary>
 2         /// 字符串判断* 任意(字符串)组成
 3         /// </summary>
 4         private static Boolean IfStar(String I,String[] s)
 5         {
 6             foreach (String i in s)
 7             {
 8                 if (!I.Contains(i))
 9                     return false;
10                 I = I.Remove(0, I.IndexOf(i) + i.Length);
11             }
12             return true;
13         }
 1         /// <summary>
 2         /// 字符串判断_ 任意(字符)组成
 3         /// </summary>
 4         private static Boolean IfUnder(String I,String[] s)
 5         {
 6             if(!I.Contains(s[0]))
 7                 return false;
 8
 9             I = I.Remove(0,I.IndexOf(s[0]));
10
11             foreach(String i in s)
12             {
13                 if (I.Contains(i) && I.IndexOf(i).Equals(0))
14                 {
15                     try
16                     {
17                         I = I.Remove(0, I.IndexOf(i) + i.Length + 1);
18                     }
19                     catch (Exception e)
20                     {
21                         I = I.Remove(0, I.IndexOf(i) + i.Length);
22                     }
23                 }
24                 else
25                 {
26                     return false;
27                 }
28             }
29
30             return true;
31         }
 1         /// <summary>
 2         /// 字符串判断 *(任意字符串) _(单个字符) 组成
 3         /// </summary>
 4         private static Boolean IfAnd(String I, String S)
 5         {
 6             foreach (String s in S.Split(‘*‘))
 7             {
 8                 if (s.Contains("_"))
 9                 {
10                     return IfUnder(I,s.Split(‘_‘));
11                 }
12                 else
13                 {
14                     if (!I.Contains(s))
15                         return false;
16                     try
17                     {
18                         I = I.Remove(0, I.IndexOf(s) + 1);
19                     }
20                     catch (Exception e)
21                     {
22                         I = I.Remove(0, I.IndexOf(s));
23                     }
24                 }
25
26             }
27
28             return true;
29
30         }
 1         /// <summary>
 2         /// 模糊判断字符串是否存在
 3         /// </summary>
 4         /// <param name="IfName">字符串</param>
 5         /// <param name="ExistString">判断中是否存在的字符串,字符串中的*表示任意字符串,_表示任意一个字符.</param>
 6         /// <returns>true/false</returns>
 7         public static Boolean orExist(String IfName,String ExistString)
 8         {
 9             //不存在 * 和 _ 并且不等 return false 如果等 return true
10             if (!ExistString.Contains("*") && !ExistString.Contains("_"))
11             {
12                 if (ExistString.Equals(IfName))
13                 {
14                     return true;
15                 }else{
16                     return false;
17                 }
18             }else{
19
20                 //只存在 * 字符
21                 if (!ExistString.Contains("_"))
22                 {
23                     return IfStar(IfName, ExistString.Split(‘*‘));
24                 }
25                 //只存在 _ 字符
26                 else if (!ExistString.Contains("*"))
27                 {
28                     return IfUnder(IfName, ExistString.Split(‘_‘));
29                 }
30                 //* 和 _ 都存在
31                 else
32                 {
33                     return IfAnd(IfName,ExistString);
34                 }
35             }
36         }    
时间: 2024-07-31 14:31:17

模糊判断字符串存在与否的相关文章

判断字符串是不是数字

NumberUtils.isNumber(str)判断字符串是不是数字或者能不能转换成数字 public class StringIsNumber { public static void main(String[] args) { Scanner s = new Scanner(System.in); String str = s.nextLine(); if(NumberUtils.isNumber(str)){ System.out.println("输入的是数字"); }els

练习:判断字符串“mingrikejijavabu”中,字符“i”出现了几次,并将结果输出。

1 // 判断字符串“mingrikejijavabu”中,字符“i”出现了几次,并将结果输出. 2 3 String str="mingrikejijavabu"; 4 5 //方法1:替换法 6 String str1=str.replace("i",""); //将字符串中i替换为空,创建新的字符串 7 System.out.println("i出现的次数为:"+(str.length()-str1.length()))

判断字符串中字母出现的次数用分割法

public class zuoye3 { public static void main(String[] args) { String a="mingrikejijavabu";//判断字符串“i”出现了几次并将其输出 int c=0;//令c为i出现的次数 String[] b=a.split("");//分隔符,把语句分割. for (String x:b)//遍历输出一遍所有字母 { if(x.equals("i"))//是否有与i相等

PHP判断字符串中是否包含指定字符串,支持中文哦

RT,随手写的 1 /** 2 * 判断字符串中是否包含指定字符串 3 * @var source 源字符串 4 * @var target 要判断的是否包含的字符串 5 * @return bool 6 */ 7 function hasstring($source,$target){ 8 preg_match_all("/$target/sim", $source, $strResult, PREG_PATTERN_ORDER); 9 return !empty($strResul

Valid Palindrome ——判断字符串是否为回文串

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41488377 Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama&

用递归法判断字符串A中包含多少个字符串B

string类提供了判断字符串B在字符串A中首次(或最后)出现的Index的方法,但有时候需要判断B在A中出现了多少次. 为此想了一个算法. 1 public static void CountIndexOf1(string A, string B,int startindex,ref int count) 2 { 3 4 int j= A.IndexOf(B,startindex); 5 if (j <= 0) 6 return; 7 count++; 8 CountIndexOf(A, B,

Java 判断是否为汉字 判断是否为乱码 判断字符串是否为双整型数字 整数 数字

/**  * 判断是否为汉字  *   * @param str  * @return  */ public static boolean isGBK(String str) {  char[] chars = str.toCharArray();  boolean isGBK = false;  for (int i = 0; i < chars.length; i++) {   byte[] bytes = ("" + chars[i]).getBytes();   if (

AC日记——判断字符串是否为回文 openjudge 1.7 33

33:判断字符串是否为回文 总时间限制:  1000ms 内存限制:  65536kB 描述 输入一个字符串,输出该字符串是否回文.回文是指顺读和倒读都一样的字符串. 输入 输入为一行字符串(字符串中没有空白字符,字符串长度不超过100). 输出 如果字符串是回文,输出yes:否则,输出no. 样例输入 abcdedcba 样例输出 yes 思路: 模拟: 来,上代码: #include<cstdio> #include<string> #include<cstring>

判断字符串中是否是数字

Java中判断字符串是否为数字的方法: 1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); i++){ System.out.println(str.charAt(i)); if (!Character.isDigit(str.charAt(i))){ return false; } } return true; } 2.用正则表达式 首先要import java.