动态填充字符串数组 [英] Populate a string array dynamically

查看:84
本文介绍了动态填充字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何动态填充字符串数组?

我希望有一些显而易见的东西我在这里失踪


Option Strict On

dim s()as string

dim sTmp as string =" test"

dim i as integer


s(i)= new string(test)

上面的行给出 - 错误隐式转换字符串为1-dim数组

char

看了一下stringbuilder并转换为contructor中的char数组,但

没有找到答案

解决方案

" Zordiac" < ZO ***** @ hotmail.com> schrieb

如何动态填充字符串数组?
我希望有一些显而易见的东西我在这里不见

Option Strict On
dim s()as string
dim sTmp as string =" test"
dim i as integer

s(i)= new string(test)
上面line give - 错误隐式转换字符串到1-dim数组
char
看看stringbuilder并转换为contructor中的char数组
但是没有找到答案




我得到一个不同的错误:变量''test''没有声明。


你想把哪些值放在数组中?

-

Armin


如何报价以及原因:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


* zo ***** @ hotmail.com (Zordiac)scripsit:

如何动态填充字符串数组?
我希望有一些明显我在这里缺少的东西

选项严格打开dim s()as string
dim sTmp as string =" test"
dim i as integer

s(i)= new string(test )
上面的行给出了 - 错误隐式转换字符串到1-dim数组
char
看看stringbuilder并在contructor中转换为char数组但是
没有找到答案




我感到很遗憾,但我无法理解你想要什么。




-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>


Zordiac写道:

如何动态填充字符串数组?
我希望有一些东西很明显我在这里失踪了

选项严格在dim s()上作为字符串
dim sTmp as string =" test"
dim i as整数

s(i)= new string(test)
上面的行给出 - 错误隐式转换字符串为1-dim数组
char
看着stringbuilder和转换为contructor中的char数组但是没有找到答案




这与你引用数组的事实有关/>
索引[ie-s(i)]并且还通过

隐式标注数组的大小,指定索引的值[即 - (测试)这是错误的,

by-by-by]


试试这个:


选项严格打开

Dim s()As String

Dim sTmp As String =" test"

Dim i As Integer


s(i)=" test"

- 或 -

s(i)= sTmp


-----

作为旁注,如果你想创建一个数组,而不是直接将它标注为

,你可以说:

Dim s()As String = {" One"," Two"" Three" }


希望这有帮助


J.

-

电子邮件列出的地址不是我的真实地址。请不要发送

有效电子邮件到该地址。


How do I dynamically populate a string array?
I hope there is something obvious that I''m missing here

Option Strict On
dim s() as string
dim sTmp as string = "test"
dim i as integer

s(i)=new string(test)
Above line gives - error implicit conversion string to 1-dim array of
char
Looked at stringbuilder and coverting to char array in contructor but
did not find an answer

解决方案

"Zordiac" <zo*****@hotmail.com> schrieb

How do I dynamically populate a string array?
I hope there is something obvious that I''m missing here

Option Strict On
dim s() as string
dim sTmp as string = "test"
dim i as integer

s(i)=new string(test)
Above line gives - error implicit conversion string to 1-dim array
of char
Looked at stringbuilder and coverting to char array in contructor
but did not find an answer



I get a different error: variable ''test'' not declared.

Which values do you want to put in the array?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


* zo*****@hotmail.com (Zordiac) scripsit:

How do I dynamically populate a string array?
I hope there is something obvious that I''m missing here

Option Strict On
dim s() as string
dim sTmp as string = "test"
dim i as integer

s(i)=new string(test)
Above line gives - error implicit conversion string to 1-dim array of
char
Looked at stringbuilder and coverting to char array in contructor but
did not find an answer



I feel sorry, but I am not able to understand what exactly you want to
do.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Zordiac wrote:

How do I dynamically populate a string array?
I hope there is something obvious that I''m missing here

Option Strict On
dim s() as string
dim sTmp as string = "test"
dim i as integer

s(i)=new string(test)
Above line gives - error implicit conversion string to 1-dim array of
char
Looked at stringbuilder and coverting to char array in contructor but
did not find an answer



It has something to do with the fact that you''re referencing the array
index [i.e.- s(i)] and also implicitly dimensioning your array by
specifying values for the indices [i.e. - (test) which is erroneous,
by-the-by]

Try this:

Option Strict On
Dim s() As String
Dim sTmp As String = "test"
Dim i As Integer

s(i) = "test"
--or--
s(i) = sTmp

-----
As a side note, if you wanted to create an array, and not dimension it
directly, you could say:
Dim s() As String = { "One", "Two", "Three" }

Hope this helped

J.
--
The email address listed is not my real address. Please do not send
valid email to that address.


这篇关于动态填充字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆