vb怎么定义字符串数组?怎么赋值?
dim strArray() ={"aaa","bbb","cccc"}
定义字符串数组_定义字符串数组长度
解释:
VB定义字符串数组与定义其它数组没大的区别,只是其赋值一般需要通过循环来获取来自某个特定来源的字符串。
Dim strSj(100) As String,本句声明一个下标为0,上标为100的共有101个元素的字符串数组。
参考资料
字符数组的定义
对,要么像char s[10]这样限定大小,要么通过初始化限定大小,如char s[]="12345";
是的 这样定义是不能通过的,首先你这是C语言风格的字符数组,在C语言中,你必须指定分配多少的内存给这个变量,所以要么是char s[10];要么就直接初始化。另外如果你想达到不分配内存的目的,c++中可以定义string,比如说 string s;然后再s="1234";或者别的作,这是可以的。
c里面声明数组的话必须指定大小。例如:char s[NUM] 其中NUM必须为常量。
定义char型指针吧,char s;
C#中如何定义string数组?
C#中定义string数组方法:
1、定义一维数组
string[] parm=new string[]{"chinese","english","japan"};
2、一维字符串数组,如果提供了初始值设定项,则还可以省略 new 运算符
string[] par3={"chinese","english","japan"};
扩展资料
C#中其他类型数组定义方式介绍:
1、定义一维int数组
int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10}; //不定长数组
int[] numbers = new int[5]{1,2,3,4,5}; //定长数组
2、定义int数组
int[,] numbers = new int[,]{{1,2,3,4,5},{1,2,3,4,5}}; //不定长数组
int[,] numbers = new int[3,3]{{1,2,3},{1,2,3}}; //定长数组
3、一维对象数组
Object[] mf4 = new Object[5] { 26, 27, 28, 29, 30 };
4、二维整数数组,初值
mf5[0,0]=1,mf5[0,1]=2,mf5[1,0]=3,mf5[1,1]=4
int[,] mf5=new int[,]{{1,2},{3,4}};
方法一:
string[] abc =new string[3];
abc[0]="1";
abc[1]="2";
abc[2]="3";
方法二:
string[] abc=new string[]{"1","2","3"};
string[] parm=new string[]{};
笨的方法
string[] abc=new string[4];
abc[0] = "aaa";
abc[1] = "bbb";
abc[2] = "ccc";
abc[3] = "ddd";
吧。
不过好像也是无穷大的,你要个无穷大的数组什么啊,那有这样的数据,如果是你的数据空间不定的话就用上面那个类吧,不过.NET中的数组是可变的,你可以动态的改变它的大小的。
string[] imagePos ={"AAA","BBB"}
string[] parm = new string[3];
parm[0] = "122";
parm[1] = "312";
parm[2] = "123";
string[] a=new string[];
string [] arr=new string[]{};
C语言 如何定义字符串数组
方法1,
使用指针数组:
#include
#include
#include
int
main()
{char
test[]={
"this
is
atest
",
"test
2",
""};
int
i=0;
while(strcmp(test[i],
"")
!=
0)
puts(test[i++]);
system(
"PAUSE
");
return
0;
}这个方法比较简单,
但是问题是这样的话,字符串是常量,无法修改。当然这个问题也可以解决,
比如使用数组赋值,
然后将
char
数组首地址赋值给某一个指针即可。
方法2,使用2维数组:
#include
#include
#include
int
main()
{char
test[][20]={
"this
is
atest
",
"test
2",
""};
int
i=0;
while(strcmp(test[i],
"")
!=
0)
puts(test[i++]);
system(
"PAUSE
");
return
0;
}这样的话,
问题就是
空间的浪费!
“C++”如何定义字符串数组?
#include
#include
int main()
{using namespace std;
string str[3] = {"ert","asd", "cvb"};
for(int i = 0; i < 3; i ++)
{cout< }} 运行这段程序就可以了,是在vs2008上测试过。注意两个地方 1.#include 2.using namespace std; 千万不要include string.h啦,string.h是C里的字符串库,而string是C++库,两者没有关系。这要弄明白连个库有什么不同,在网上搜搜就有。 C++里的String是包含在std命名空间里的,所以要加上第二句。 比如说你要定义一个字符型的:char A[20]="你要写的字符串"。 一个字符串能够在定义字符数组时作为初始化数据被存入到数组中,但不能通过赋值表达式直接赋值。例如:char mark[10];mark=''C program''; /赋值不合法/ 而正确的: char word[20] = “Dictionary” char name[ ] = “Tommy” char c[10] = {‘s’,’t’,’r’,’i’,’n’,’g’,’\0’};一个字符’\0’必须有,为字符串结束标志。 版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至836084111@qq.com 举报,一经查实,本站将立刻删除。