zoukankan      html  css  js  c++  java
  • 简单获取字符串中间值(KEY)

    简单获取字符串中间值。

    暂时只知道这种简单的方法。

    菜鸟方法,

    1 public string substringone(string firstkey, string lastkey, string str)
    2 {
    3 int startIndex = str.IndexOf(firstkey);
    4 int lastIndex = str.IndexOf(lastkey);
    5 string newstr = str.Substring(startIndex, lastIndex);
    6 return substringlast(firstkey, lastkey, newstr);
    7 }
    8
    9 private string substringlast(string firstkey, string lastkey, string str)
    10 {
    11 int startIndex = str.IndexOf(firstkey);
    12 int lastIndex = str.IndexOf(lastkey);
    13 return str.Substring(startIndex, lastIndex).Replace(firstkey,"");
    14 }

    不知道还有没有其他方法。暂时记录在这里,如果有什么其他方法 希望大家留言给我 感激不尽。

    调用。

    1 static void Main(string[] args)
    2 {
    3 string str="<?xml version=\"1.0\" encoding=\"GB2312\"?> <EnterpriseInfo EnterpriseNumber=\"74260279\" EnterpriseName=\"**********\" EnterpriseShortName=\"***********\" EnterprisePhone=\"*********\" EnterpriseAddress=\********\" EnterpriseEmail=\"*************\" >";
    4 string fristkey = "seNumber=\"";
    5 string lastKey = "\" EnterpriseName";
    6 substringone(fristkey, lastKey, str);
    7 }
  • 相关阅读:
    26个精选的JavaScript面试问题
    用js实现随机选取10–100之间的10个数字,存入一个数组,并排序
    小程序布局中class='container'的bug
    PHP接收数据数据包的几个方式
    LINUX命令
    VMware的下载安装
    php中Sessions
    php中Cookies
    php文件上传
    php文件处理
  • 原文地址:https://www.cnblogs.com/yueyue184/p/2085232.html
Copyright © 2011-2022 走看看