最后机会分割,子字符串等 [英] Last chance split, substring etc
问题描述
你好,
这是我最后的机会..它仍然无法正常工作.
我将尝试简单地解释一下:
我有一个数据库
我有一个文本文件(vcf)
我的应用程序显示数据库中的信息.
我想导入文本文件,显示存储在数据库中的我的应用程序中将有一个新的联系人显示.
这是文本文件中的信息:
hello,
this is my last chance.. it''s still not working.
I will try to explain it simple:
I have a database
I have a textfile (vcf)
my App shows the info that is in the database.
I want to import the textfile show there will be a new contact show in my app saved in the database.
this is the info in the textfile:
BEGIN:VCard
VERSION:2.1
N:De Jong
FN:Anne
TEL;WORK;VOICE:0512540540
TEL;WORK;VOICE:0512540540
TEL;HOME;VOICE:06-11299731
TEL;CELL;VOICE:06-11299731
TEL;VOICE:0512 540221
TEL;WORK;FAX:0512 540540
TEL;FAX:0512 540221
ADR;WORK;PREF:;;Sjoerd Veltmanstraat 15;Drachten;;9203 NJ
ENCODING=QUOTED-PRINTABLE:Sjoerd Veltmanstraat 15
URL;HOME:www.epixfotostudio.nl
URL;WORK:www.epixfotostudio.nl
EMAIL;PREF;INTERNET:odejong@epixfotostudio.nl
END:VCARD
从N开始直到将传真插入数据库.
从Adres将不会被插入.这是我要插入的代码:
From N till Fax is inserted into the database.
From the Adres will not be inserted. This is my code to insert:
Do While objReader.Peek >= 1
strRegel = objReader.ReadLine(1) 'Elke regel/lijn wordt 1 voor 1 gelezen:
strWaarde = strRegel.Split(":") 'De waarde van elke regel wordt gesplits d.m.v. ":":
strWaarde = strRegel.Split(";")
'strAdgegevens = strAdwaarde.Split(";")
'Onderstaande Boolean zorgt ervoor dat dubbele info weg gehaald worden:
'----------------------------------------------------------------------
Dim blnDubbel As Boolean
Select Case UCase(strWaarde(0)) '(0) = het gedeelte voor ":" en (1) komt daarna:
Case "BEGIN", "VERSION", "END", _
"ENCODING=QUOTED-PRINTABLE"
Case "N"
strNaam = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbTab)
Case "FN" 'Voornaam:
strVoornaam = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbCrLf)
Case "TEL;WORK;VOICE" 'Telefoon op het werk:
If blnDubbel = False Then
strTelWerk = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbTab)
blnDubbel = True
End If
Case "TEL;HOME;VOICE" 'Telefoon thuis:
strTelThuis = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbCrLf)
Case "TEL;CELL;VOICE" 'Mobiele telefoon:
strMobiel = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbTab)
Case "TEL;VOICE" 'Overige nummers:
strOverig = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbCrLf)
Case "TEL;WORK;FAX" 'Fax op het werk:
strFaxWerk = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbTab)
Case "TEL;FAX" 'Fax thuis:
strFaxThuis = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbCrLf)
Case "ADR;WORK;PREF:" 'Adresgegevens:
strAdgegevens = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbCrLf)
Case "URL;HOME:" 'Website Thuis:
strUrlThuis = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbTab)
Case "URL;WORK:" 'Website Werk:
strUrlWerk = strWaarde(1)
sbBuilder.Append(strWaarde(1) & vbCrLf)
Case "EMAIL;PREF;INTERNET:" 'Email adres:
strMail = strWaarde(1)
sbBuilder.Append(strWaarde(1))
Case Else
sbBuilder.Append(strWaarde(1) & vbCrLf)
End Select
Loop 'Het proces wordt herhaald:
objReader.Close()
frmVCard.txtVCard.Text = sbBuilder.ToString
Dim strInsert As String
'Waardes invoegen in de velden van de tabel Relaties:
'----------------------------------------------------
'INSERT & VALUES lijst:
strInsert = "INSERT INTO Relaties (B22_relnr, B22_rel_soort, B22_naam, B22_voornaam_etc, " _
& "B22_adres, B22_postcode, B22_plaats, B22_telefoon1, B22_telefoon2, " _
& "B22_mobielnr, B22_faxnummer, B22_email, B22_www_adres, B22_zoeknaam) " _
& " VALUES (" & intNummer & ", '" & strSoort & "', '" & strNaam _
& "', '" & strVoornaam & "', '" & strAdres _
& "', '" & strPostcode & "', '" & strPlaats & "', '" & strTelWerk _
& "', '" & strTelThuis & "', '" & strMobiel & "', '" & strFaxWerk _
& "', '" & strMail & "', '" & strUrlWerk & "', '" & strZoek & "' )"
Dim ds_B22 As New OdbcCommand 'ds_B22 is de tabel Relaties.
ds_B22.CommandType = Data.CommandType.Text
ds_B22.CommandText = strInsert 'Zorgt ervoor dat de informatie wordt toegevoegd aan de database.
ds_B22.Connection = cnn
ds_B22.ExecuteNonQuery()
If MsgBox _
("De V-Card is geïmporteerd", 0, "V-Card is geïmporteerd") Then
Exit Sub
End If
我希望有人能帮助我.
我已经从该论坛下载了一个vcf文件,但仍然没有得到它.
只是给我一个例子,展示如何将信息放入数据库.
谢谢
I hope someone can help me out.
I have download a vcf file from this forum but I still dont get it.
just give me an example to show how to get the info into the database.
Thanks
推荐答案
让我惊讶的第一件事是,您正在覆盖您的strWaarde
变量.我的猜测是,如果注释掉对该变量的第二个赋值,那么您将解决问题.它应该是这样的:
The first thing that jumps out at me is the fact that you are overwriting yourstrWaarde
variable. My guess is that if you comment out the second assignment to that variable that you will fix your issue. Here is what it should look like:
strRegel = objReader.ReadLine(1)
strWaarde = strRegel.Split(":")
'strWaarde = strRegel.Split(";")
注释掉的行将以错误的方式分割行.您需要在冒号处而不是在分号处进行拆分,因为您希望查看整个标识符部分的strWaarde(0)
值,而不仅仅是它的第一部分.
The commented out line would split the line the wrong way. You need to split it at the colon, not the semi-colon since you are expecting to look at the strWaarde(0)
value for the entire identifier portion, not just the first part of it.
我的项目完成了!
谢谢大家的帮助
my project is done!
everyone thanks for your help
我的项目完成了!
谢谢大家的帮助!
My project is done!
thanks everyone for your help!
这篇关于最后机会分割,子字符串等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!