|
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Public Class JSstring
Dim vb As Boolean
Private Sub JSstring_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
If txtFile.Text.Length = 0 Then
MsgBox("Select a JavaScript file")
Return
End If
vb = CBool(IIf(rbVb.Checked, True, False))
Dim result As String
If vb Then
result = "Dim sb As StringBuilder = New StringBuilder()" + vbCrLf
result += "sb.Append(""<script type=""""text/javascript"""" language=""""javascript"""">"")" + vbCrLf + vbCrLf
Else
result = "StringBuilder sb = new StringBuilder();" + vbCrLf
result += "sb.Append(""<script type=\""text/javascript\"" language=\""javascript\"">"");" + vbCrLf + vbCrLf
End If
Dim strContents As String = ""
Dim objReader As StreamReader
Try
objReader = New StreamReader(txtFile.Text)
strContents = objReader.ReadToEnd()
objReader.Close()
Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try
Dim str() As String = Regex.Split(strContents.Trim, vbLf)
Dim sb As StringBuilder = New StringBuilder()
For i As Integer = 0 To str.Length - 1
str(i) = str(i).Replace("""", """""")
str(i) = str(i).TrimEnd(Chr(13))
If vb Then
sb.Append("sb.Append(""")
Else
sb.Append("sb.Append(@""")
End If
sb.Append(str(i))
sb.Append(""")")
If Not vb Then
sb.Append(";")
End If
sb.Append(vbCrLf)
Next
result += sb.ToString
result = result.TrimEnd(Chr(10))
result += vbCrLf + vbCrLf
result += "sb.Append(""</script>"")"
If Not vb Then
result += ";"
End If
result += vbCrLf + vbCrLf
If vb Then
result += "Dim js as String = sb.ToString"
result += vbCrLf
result += "ClientScript.RegisterStartupScript(Me.GetType(), ""JScript"", js)"
Else
result += "string js = sb.ToString();"
result += vbCrLf
result += "ClientScript.RegisterStartupScript(this.GetType(), ""JScript"", js);"
End If
txtResult.Text = result
End Sub
Private Sub btnFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFile.Click
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
txtFile.Text = OpenFileDialog1.FileName
End If
End Sub
Private Sub btnClipboard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClipboard.Click
Clipboard.Clear()
If txtResult.Text.Trim.Length > 0 Then
Clipboard.SetText(txtResult.Text)
End If
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Lifelong software developer. From IBM mainframes to Microsoft .Net, and lots in between.
Born and raised in Vilnius, Lithuania. Today live in Toronto, Ontario. Tomorrow - who knows?