zoukankan      html  css  js  c++  java
  • 一些字符串的操作

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    Test();
    }

    public void Test()
    {
    string str = "Now is the time for all good men to come to the aid of their party.";
    int start;
    int at;

    Console.WriteLine();
    Console.WriteLine(
    "All occurrences of 't' from position 0 to {0}.", str.Length - 1);
    //Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
    Console.Write("The letter 't' occurs at position(s): ");

    at
    = 0;
    start
    = 0;
    //获取每个t的位置
    while ((start < str.Length) && (at > -1))
    {
    at
    = str.IndexOf('t', start);
    if (at == -1) break;
    Console.Write(
    "{0} ", at);
    start
    = at + 1;
    }

    string a = "a bcde";
    int index = a.IndexOf('e');
    int index1 = a.IndexOf('e', 0);
    //获取带星号的ip
    string ip = "127.0.0.123";
    string ip2 = "123456";
    string index2 = ip2.Substring(0,3);
    string changeip = ip.Substring(0,ip.LastIndexOf(".")+1)+"*";

    }

    }

  • 相关阅读:
    EditPlus保存文件时不生成其备份文件的方法
    一台电脑同时运行多个tomcat配置方法
    Dom4j写XML
    .....
    编程备忘录
    背包问题
    chrome新版不再支持-webkit-text-size-adjust
    安装grunt需要的grunt插件
    初学web前端
    心情烦躁、、
  • 原文地址:https://www.cnblogs.com/aiyp1314/p/2100419.html
Copyright © 2011-2022 走看看