Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何通过消除循环来简化此代码_Arrays_Vb.net - Fatal编程技术网

Arrays 如何通过消除循环来简化此代码

Arrays 如何通过消除循环来简化此代码,arrays,vb.net,Arrays,Vb.net,我必须使用vb.net将每个单词的首字母大写。为此,我使用以下代码它为我提供了正确的结果。让我知道他们做同样事情的最简单方法是什么?以下是我使用的代码: Dim input As String = "something anything nothing" Dim array() As String = input.Split(" ") Dim output As String = "" For i As Integer = 0 To array.Length -

我必须使用
vb.net
将每个单词的首字母大写。为此,我使用以下代码它为我提供了正确的结果。让我知道他们做同样事情的最简单方法是什么?以下是我使用的代码:

    Dim input As String = "something anything nothing"
    Dim array() As String = input.Split(" ")
    Dim output As String = ""
    For i As Integer = 0 To array.Length - 1
        Dim temp() As Char = array(i).ToCharArray
        output &= Char.ToUpper(temp(0)) & array(i).ToString.Substring(1) & " "
    Next
    MsgBox(output)
输出将是


有事无事

以下是最简单的方法之一:您也可以尝试
LINQ
Regex
等来简化代码:

 Dim input As String = "something anything nothing"
 Dim output As String = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input)
 MsgBox(output)
您需要导入
Imports System.Globalization
才能使用此代码