Vb.Net将定界数据推送到不同的变量类型 [英] Vb.Net Push Delimited Data to Different variable types

查看:146
本文介绍了Vb.Net将定界数据推送到不同的变量类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,

我想知道您是否可以帮助我,我有一个文本文件,管道为"|"定界,我的问题是其中有几种变量类型,例如

Good Morning,

I am wondering if you can help me, i have a text file that is pipe "|" delimited, the issue i have is that there are several variable types within this, for example

5009|0011730|00|0000|0000|0000|N|N|29/03/2007|N|      0|Y|      0|    0|      0.00 |06|655|A|  |A| | |               



这是从具有固定宽度和零抑制的COBOL系统中获取的,我正尝试将其插入到SQL数据库中.

在COBOL中,您可以将PIC定义为字段的长度,这样会将数据向下推到相应的值,但是鉴于我有200,000条记录,并且大约有20种不同类型的数据覆盖了2000多个字段,我不想必须手动键入每个变量.

是否有任何类型的自动"填充可以帮助我解决此问题,例如:



This has been taken from a COBOL system with fixed width and Zero Suppression and i am trying to insert this into a SQL database.

In COBOL you can define PIC''s to the length of the field and it would push the data down through the values however given i have over 200,000 records and there are about 20 different types of data covering over 2000 fields, i do not want to have to type each variable manually.

Is there any sort of ''Auto'' fill that can help me with this, for example:

Public Structure DataType_1
    Sub New(ByVal DelimitedString)
        'Do Something Here
        'to push the values without
        'having to write up each variable'
        'and assign it a value

    End Sub
    Public Var1 As Integer
    Public Var2 As Integer
    Public Var3 As Integer
    Public Var4 As Integer
    Public Var5 As Integer
    Public Var6 As Integer
    Public Var7 As String
    Public Var8 As String
    Public Var9 As Date
    ' and so no per each delimted value

End Structure



由此,我可以从中创建SQL并将其推送到数据库表中.我不确定分配每个变量是否正确,也许是集合?

任何想法都将有所帮助.



From this i can then create the SQL from it to push it into a database table. I am not sure if assigning each variable is the right way either, maybe a collection?

Any thoughts would be helpful.

推荐答案

我将定义自定义类,如下所示:
I would define custom class like this:
Public Class MyData
	Private Var1? As Integer '(Of Nullable)
	Private Var2? As Integer
	Private Var3? As Integer
	Private Var4? As Integer
	Private Var5? As Integer
	Private Var6? As Integer
	Private Var7 As String 
	Private Var8 As String 
	Private Var9? As Date 

	Public Sub New(ByVal PipedString As String)
		Dim data As String() = PipedString.Split("|")
		Var1 = data(0)
		Var2 = data(1)
		Var3 = data(2)
		Var4 = data(3)
		Var5 = data(4)
		Var6 = data(5)
		Var7 = data(6)
		Var8 = data(7)
		Var9 = Convert.ToDateTime(data(8), New System.Globalization.CultureInfo("de-DE"))
	End Sub
	
        Public Property Data1 As Integer
		Get 
			Return Var1
		End Get
		Set (value As Integer)
			Var1 = value
		End Set
	End Property
	
	'define other properties here



	Public Overrides Function ToString() As String
		Return "Date is: " & Var9.ToString()
	End Function

End Class



用法:



Usage:

Dim s As String  = "5009|0011730|00|0000|0000|0000|N|N|29/03/2007|N|      0|Y|      0|    0|      0.00 |06|655|A|  |A| | |  "


Dim md As MyData = New MyData(s)
Console.WriteLine("{0}", md.ToString())

md.Data1 = 5010
Console.WriteLine("{0}", md.Data1)


这篇关于Vb.Net将定界数据推送到不同的变量类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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