开发者

Text formatting isn't producing expected results

开发者 https://www.devze.com 2023-04-10 06:28 出处:网络
I\'m trying to make a simple tool to format SQL code so that I can use it in VB. When I put in the following:

I'm trying to make a simple tool to format SQL code so that I can use it in VB. When I put in the following:

USE master
CREATE DATABASE netGuest
GO

I get...

"USE master" & vbCrLf & _"
CREATE DATABASE netGuest" & vbCrLf & _"
GO" & vbCrLf & _"

So it almost works. Really the only thing not working is that the lines are ending w开发者_运维技巧ith the " rather than starting with them.

Here's my code:

Protected Sub btnConvert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConvert.Click
    If txtVB.Text IsNot Nothing Then : txtVB.Text = "" : End If

    Dim input() As String = txtSQL.Text.Split(vbCrLf)
    For i As Integer = 0 To UBound(input) - 1
        txtVB.Text = """" & input(i) & """ & vbCrLf & _"
    Next
End Sub

Thanks in advance for the help.


It's because the split is not cutting of the vbCrLf but leave it there.

try this.

Dim textstring = "select *" & vbCrLf & "from table " & vbCrLf & "Go"
Dim output As String = ""
Dim input() As String = textstring.Split(CChar(ControlChars.CrLf))
output = """" & input(0) & """ & vbCrLf & _" & ControlChars.CrLf
For i As Integer = 1 To UBound(input)
    output &= """" & input(i).Substring(1) & """ & vbCrLf & _" & ControlChars.CrLf
Next
Console.WriteLine(output)
Console.ReadLine()
0

精彩评论

暂无评论...
验证码 换一张
取 消