• vb.net 字符串的操作 应用


    Module Module1
    
        Sub Main()
            ' 定义3个字符串变量
            Dim str1, str2, str3 As String
            '给str1,str2付初值
            str1 = "Hello" : str2 = "World"
            Console.WriteLine("方法Concat")
            '连接一个或多个字符串
            Console.WriteLine("str1={0},str2={1},String.Concat(str1,str2)={2}", str1, str2, String.Concat(str1, str2))
            '判断字符串中是否具有相同的值返回类型为布尔型
            Console.WriteLine("方法Equals")
            Console.WriteLine("str1={0},str2={1},String.Equals(str2)={2}", str1, str2, str1.Equals(str2))
            '在字符串中指定索引位置插入指定的字符串
            Console.WriteLine("方法Insert")
            str1 = "0123456789" : str2 = "aaa"
            Console.WriteLine("str1={0},str2={1},str1.Insert(5,str2)={2}", str1, str2, str1.Insert(5, str2))
            '左右对齐字符串中的字符
            Console.WriteLine("方法PadLeft/PadRight")
            str1 = "World" : str2 = "世界"
            Console.WriteLine("str1={0}", str1)
            Console.WriteLine("str1.PadLeft(8,""*"")={0},str.PadRight(8,""*"")={1}", str1.PadLeft(8, "*"), str1.PadRight(8, "*"))
            Console.WriteLine("str1={0}", str2)
            Console.WriteLine("str2.PadLeft(8,""*"")={0},str2.PadRight(8,""*"")={1}", str2.PadLeft(8, "*"), str2.PadRight(8, "*"))
            '找出指定字符串或字符转在此字符串中的第一个、最后一个匹配项的索引位置
            Console.WriteLine("方法IndexOf/LastIndexOf")
            str1 = "Visual Basic.NET,ASP.NET,C#.NET"
            Console.WriteLine("str1={0}", str1)
            Console.WriteLine("str1.IndexOf(""NET"")={0},str1.LastIndexOf(""NET"")={1}", str1.IndexOf("NET"), str1.LastIndexOf("NET"))
            '将字符串中的字符复制到字符串数组
            Console.WriteLine("方法ToCharArray")
            str2 = str1.ToCharArray(str1.IndexOf("NET"), 3)
            Console.WriteLine("str1={0}", str1)
            Console.WriteLine("str1.ToCharArray(str1.IndexOf(""NET""),3)={0}", str2)
            '在指定字符串数组的每个元素之间串联指定的分隔符,产生单个串联的字符串
            Console.WriteLine("方法Join")
            Dim myArray(3) As String
            myArray(0) = "I" : myArray(1) = "am" : myArray(2) = "a" : myArray(3) = "student"
            For i As Integer = 0 To 3
                Console.Write("myArrat({0})={1}", i, myArray(i))
            Next
            Console.WriteLine()
            Console.WriteLine("String.Join(""*"",myArray)={0}", String.Join("*", myArray))
            '此字符串中删除指定个数字符
            Console.WriteLine("方法Remove")
            str1 = "0123456789"
            Console.WriteLine("str1={0},str1.Remove(2,3)={1}", str1, str1.Remove(2, 3))
            '将此字符串指定字符串字符的所有匹配项代替为其他指定字符串
            Console.WriteLine("方法Replace")
            str2 = "123"
            str3 = "abc"
            Console.WriteLine("str1={0}, str2={1}, str3={2}, str1.Replace(str2, str3)={3}", str1, str2, str3, str1.Replace(str2, str3))
            '从此字符串检索字符串
            Console.WriteLine("方法SubString")
            Console.WriteLine("str1={0},str1.Substring(3,4)={1}", str1, str1.Substring(3, 4))
            Console.ReadLine()
        End Sub
    
    End Module
    


     

  • 相关阅读:
    Codeforces Round #744 (Div. 3) (CF1579) 题解
    Codeforces Round #748 (Div. 3) (CF1593)题解
    NOIP2018初赛游记
    模板:高精度
    博客园,初见安~~
    20200211学习
    nyoj 1103 区域赛系列一多边形划分
    南阳oj 845 无主之地1
    hdu 2080 夹角有多大II
    hdu 分拆素数和
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3141263.html
Copyright © 2020-2023  润新知