如何在VB.net中拆分和替换 [英] How to split and replace in VB.net

查看:69
本文介绍了如何在VB.net中拆分和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

您可以使用以下两种方法之一:在Split上使用Replace代替:
You can do it one of two ways: use Replace instead on Split:
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中拆分和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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