问题描述
vXMLStream = YYYYMM ="200502" ename ="RAJ" age ="23" sex ="Male" category ="Poor" edu_qualification ="BBA" community ="SC"宗教信仰="HINDU"职业=农民" month_income ="2000"
在这里,我将其拆分并存储在数组变量中.为此,我尝试了以下.因为在这里,我想单独替换一个数组位置为职业=农民".
最后,我想连接所有数组索引并存储在vXMLStream变量中.
vXMLStream = YYYYMM="200502" ename="RAJ" age="23" sex="Male" category="Poor" edu_qualification="BBA" community="SC" religion="HINDU" occupation="farmer" month_income="2000"
Here i splited this and to stored in an array variable. for that i tried the following. Because here i want to replace occupation="farmer" this one array position alone alone.
and finally i want to concatenate all the array indexes and stored in the vXMLStream variable.
Dim sourceString As String = vXMLStream
Dim arrayOfStrings() As String = sourceString.Split(" ")
System.Web.HttpContext.Current.Response.Write("<script language='javascript'>alert('The following errors have occurred:\n" + arrayOfStrings(2) + "' );</script>")
但是现在一旦我打印了数据,我就得到了这样的输出:-
YYYYMM ="200502"
ename ="RAJ"
age ="23"
sex ="Male"
category =可怜"
edu_qualification ="BBA"
community ="SC"
宗教信仰="HINDU"
职业=农民"
在这里,我想替换它(occupation ="farmer",这是静态的),最后我想连接所有数组索引并存储在vXMLStream变量中.
请为此帖子发布解决方案
But Now once i print the data i am getting output like this:-
YYYYMM="200502"
ename="RAJ"
age="23"
sex="Male"
category="Poor"
edu_qualification="BBA"
community="SC"
religion="HINDU"
occupation="farmer"
Here i want to replace this (occupation="farmer" this is static one) finally i want to concatenate all the array indexes and stored in the vXMLStream variable.
please post solution for this post
推荐答案
Dim output as String = sourceString.Replace("occupation=""farmer""", "")
或者在循环中从列表中删除字符串
Or remove the string from the list in a loop
For i As Integer = 0 To arrayOfStrings.Length - 1
If arrayOfStrings(i) = "occupation=""farmer""" Then
arrayOfStrings(i) = ""
End If
Next
串联很简单:
To concatenate is simple:
vXMLStream = String.Join(" ", arrayOfStrings)
这篇关于如何在VB.net中拆分和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!