本文介绍了将一个数组元素复制到另一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个代码来逐个字符读取文本框并将这些字符复制到另一个数组中.一旦出现空格字符,该过程应停止.程序在运行时给出了参数null异常.任何解决方案.

这是代码.

I have written a code to read a text box character by character and copy the characters into another array. As soon as the space character occurs the process should stop. the Program is giving argument null exception at runtime. Any solutions.

Here is the code.

Private Sub file_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles file_open.Click
Dim objreader As New System.IO.StreamReader(file_name.Text)
    TextBox1.Text = objreader.ReadLine

    TextBox1.Text = TextBox1.Text & objreader.ReadLine & vbCrLf

    Dim myArray() As Char
    Dim myArray2() As Char

    myArray = Me.TextBox1.Text.ToCharArray
    For i As Integer = 1 To 70
        If myArray(i) <> " " Then

        Else
            Array.Copy(myArray, myArray2, i)     'exception here

        End If
    Next

End Sub

推荐答案


Dim myArray1 As List(Of Char) = TextBox1.Text.ToCharArray
Dim myArray2 As List(Of Char) = New List(Of Char)

For Each c As Char In myArray1
    If c <> " " Then
        myArray2.Add(c)
    Else
        Exit For
    End If
Next




干杯




Cheers


这篇关于将一个数组元素复制到另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:13