将字符串数组中的特定索引添加到其他字符串数组 [英] add particular index from string array into other string array

查看:89
本文介绍了将字符串数组中的特定索引添加到其他字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有字符串数组(字符串[])

有一些值,如



ad23g4



ad25



ad1g5



string [] newsval = new string [ ] {ad23g4,ad25,ad1g5}



string [] testother = new string [] {};



我有xml在哪里



ad23g4 =true

ad25 =false

ad1g5 =true





现在来自上面



i检查if(status ==true){



将newsval [1]添加到testother [1]

将newsval [3]添加到testother [3]



}



< b> 我不想添加newsval [2]因为它是假的



如何在asp.net中执行此操作



问候

maulik shah

I have string array (string[])
which has some values like

ad23g4

ad25

ad1g5

string[] newsval=new string[] {"ad23g4","ad25","ad1g5"}

string[] testother=new string[]{""};

and i have xml where

ad23g4 ="true"
ad25="false"
ad1g5="true"


now from above

i check if( status=="true"){

add newsval[1] into testother[1]
add newsval[3] into testother[3]

}

i dont want to add newsval[2] as it is false

how to do this in asp.net

regards
maulik shah

推荐答案

读取xml并存储在字典中,键值为字符串(键)和

布尔值(值)

仅对字典进行过滤以获得真值并获得计数

将数组初始化为

Read the xml and store it in a dictionary with key value as string(key) and
boolean(value)
Filter the dictionary for only true values and get the count
Initialise an array as
int count=0; // get from dictionary
        string[] testother = new string[count];



并迭代字典以匹配数组中的字符串

并将值分配给新数组..


and iterate the dictionary to match the string in the array
and assign the values to the new array..


这篇关于将字符串数组中的特定索引添加到其他字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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