我想分割功能将连续的字符串字符分成12个字符,然后插入数据库。 [英] I want split function to split continuous string characters into only 12 character then insert into database.
本文介绍了我想分割功能将连续的字符串字符分成12个字符,然后插入数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Private Sub SMSPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles comPort.DataReceived
Dim str As String = ""
Dim temp As String = ""
objCon.GetConnectionString()
If e.EventType = SerialData.Chars Then
SMSPort.DtrEnable = True
System.Threading.Thread.Sleep(100)
tempp = SMSPort.ReadExisting().Replace("", "").Trim()
//' iwant to add here split function to split more than 12 charcters into only 12 character then give entry into database..
'For i As Integer = 1 To tempp.Length Step 12
' Debug.Write(Mid(tempp, i, 12))
If tempp <> "" Then
objCon.GetConnectionString()
objCon.GetConnection("Insert into tblAttended(Id,Status,Date,Time)values('" + tempp.ToString() + "','In','" + System.DateTime.Today.ToShortDateString() + "','" + DateTime.Now.ToShortTimeString() + "')")
ListView1.Items.Add(tempp)
txtUniqueNumber.Text = tempp.Trim()
ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
End If
'Next i
Control.CheckForIllegalCrossThreadCalls = False
End Sub
推荐答案
使用此 -
use this-
If tempp.Length > 12 Then tempp = tempp.Substring(0, 12)
请标记为答案if帮助。
please mark as answer if helped.
Ankit thnks ...这里有一个大问题..使用此代码
if tempp.Length> ; 12然后tempp = tempp.Substring(0,12)
假设36个字符串然后我只能分成12个字符..但我想存储将整个字符串(36个字符)分成3个不同的子字符串并存储到数据库中...
请尽快指导...
我的代码是这样的..
Ankit thnks... one big question over here.. with this code
"If tempp.Length > 12 Then tempp = tempp.Substring(0, 12)"
suppose 36 characters string then i can divide into 12 characters once only.. but i want to store that whole string (36 characters) into 3 differnt substring nd wnt to store into database...
kindly guide as soon as posible ...
my code is like this..
Dim str As String = ""
Dim temp As String = ""
objCon.GetConnectionString()
If e.EventType = SerialData.Chars Then
SMSPort.DtrEnable = True
System.Threading.Thread.Sleep(100)
tempp = SMSPort.ReadExisting().Replace(">", "").Trim()
For i As Integer = 1 To tempp.Length Step 12
Debug.Write(Mid(tempp, i, 12))
If tempp <> "" Then
objCon.GetConnectionString()
objCon.GetConnection("Insert into tblAttended(Id,Status,Date,Time)values('" + tempp.ToString() + "','In','" + System.DateTime.Today.ToShortDateString() + "','" + DateTime.Now.ToShortTimeString() + "')")
'ListView1.Items.Add(tempp)
txtUniqueNumber.Text = tempp.Trim()
'ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
End If
Next i
这篇关于我想分割功能将连续的字符串字符分成12个字符,然后插入数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文