/**
* 获取目标字符串在字符串中第N次出现的位置
* @file name
* @author xiehongwei
* @date 2017-8-2 下午3:29:09
* @param source 源字符串
* @param target 目标字符串
* @param n 出现位置
* @return
*/
public static int getCharacterPosition(String source, String target, int n) {
// 这里是获取目标符号的位置
Matcher slashMatcher = Pattern.compile(target).matcher(source);
int mIdx = 0;
while (slashMatcher.find()) {
mIdx++;
// 当目标符号第N次出现的位置
if (mIdx == n) {
break;
}
}
return slashMatcher.start();
}

获取目标字符串在字符串中第N次出现的位置的更多相关文章

  1. 获取一个字符串Hello world中world首次出现的位置

    获取一个字符串Hello world中world首次出现的位置 var str=“Hello world!” document.write(str.indexOf("world") ...

  2. ASP.NET 4.0 ListView等容器控件中获取ClientID值与HTML中自动生成ID字符串不一样问题。

    ASP.NET 4.0 中 ClientIDMode的属性 可以设置获取不同ID格式的值. 项目中遇到的问题: 1.ListView1 ItemDataBound事件中,获取ClientID结果与自动 ...

  3. SQL Server获取下一个编码字符串的实现方案分割和进位

        我在前一种解决方案SQL Server获取下一个编码字符实现和后一种解决方案SQL Server获取下一个编码字符实现继续重构与增强两篇博文中均提供了一种解决编码的方案,考虑良久对比以上两种方 ...

  4. C字符串和C++中string的区别 &&&&C++中int型与string型互相转换

    在C++中则把字符串封装成了一种数据类型string,可以直接声明变量并进行赋值等字符串操作.以下是C字符串和C++中string的区别:   C字符串 string对象(C++) 所需的头文件名称 ...

  5. C字符串和C++中string的区别 &&&&C++中int型与string型互相转换

    在C++中则把字符串封装成了一种数据类型string,可以直接声明变量并进行赋值等字符串操作.以下是C字符串和C++中string的区别:   C字符串 string对象(C++) 所需的头文件名称 ...

  6. c# 用正则表达式获取开始和结束字符串中间的值

    c# 用正则表达式获取开始和结束字符串中间的值 /// <summary> /// 获得字符串中开始和结束字符串中间得值 /// </summary> /// <para ...

  7. Java 字符串比较,String 中的一些方法 == 和 equals 的详解

    "==" 是比较的是两个对象的内存地址,而equals方法默认情况下是比较两个对象的内存地址. 1.String str = "hello"  生成的字符串,首 ...

  8. 获取url "?" 后面的字符串

    今天写了一个URL “?” 后面的字符串 来改变当前页面的状态 首先需要获取当前页面的URL console.log(widow.location) 之后页面就会打印出来当前的URL 之后我们获取UR ...

  9. MVC二级联动使用$.ajax方法获取后端返回的字符串

    在"MVC二级联动使用$.getJSON方法"中使用$.getJSON()获取后端返回的JSon. 本篇使用jQuery的$.ajax()获取后端返回的字符串,实现二级联动.   ...

随机推荐

  1. flask入门(三)

    表单 request.form 能获取POST 请求中提交的表单数据.但是这样不太安全,容易受到恶意攻击.对此,flask有一个flask-wtf扩展,用于避免这一情况 在虚拟环境下用pip inst ...

  2. Suggestions On Setting LED Holiday Light

    We all like the cheerful glow of holiday lights, so the process goes seamless from start to finish. ...

  3. 【C语言】输入一个整数x并判断x是否存在于数组a中

    #include<stdio.h> int main() { ] = { ,,,,,,,, };//数组初始化 printf("请输入要查找的数据:\n"); scan ...

  4. 文艺平衡树 lg3391(splay维护区间入门)

    splay是支持区间操作的,先做这道题入个门 大多数操作都和普通splay一样,就不多解释了,只解释一下不大一样的操作 #include<bits/stdc++.h> using name ...

  5. unity命令行参数

    Typically, Unity will be launched by double-clicking its icon from the desktop but it is also possib ...

  6. Request继承体系

    ServletRequest——接口 ↑继承 HttpServletRequest——接口 ↑实现 org.apache.catalina.connector.RequestFacade——类(Tom ...

  7. Redis Distributed lock

    using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using ...

  8. requests.packages.urllib3.exceptions.ProxySchemeUnknown: Not supported proxy scheme

    python3 -m pip install -U requests[socks]

  9. 题解【洛谷P1074】[NOIP2009]靶形数独

    题面 题解 一开始写了一个朴素的数独,无任何剪枝优化,得到了\(55\)分的好成绩. 就是这道题加一个计算分数. 代码如下(\(\mathrm{55\ pts}\)): /************** ...

  10. 题解【POJ3252】Round Numbers

    Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...