I was trying hard to find a utility that would do all this for me and relieve me from this pain. However, it looked like such thing just didn't exist in the vast space of the internet or such was just my luck. So, I decided to create one myself. All the more, it didn't look like a very hard task.
Using the Code
<script> tags, is now contained in the string variable and is registered with the page by the
ClientScript.RegisterStartupScript method. For your convenience, all generated code may be copied into the clipboard.
Points of Interest
In order to do the job, the
Streamreader class is used to read the text file:
Dim objReader As StreamReader
objReader = New StreamReader(txtFile.Text)
strContents = objReader.ReadToEnd()
Catch Ex As Exception
StringBuilder class methods perform all the needed operations to save and transform the strings, such as dealing with quotation marks in the text depending on the output language, constructing valid VB or C# statements and so on.
str(i) = str(i).Replace("""", """""")
str(i) = str(i).TrimEnd(Chr(13))
If vb Then
If Not vb Then
To copy the generated code snippet into the clipboard, I'm using a
If txtResult.Text.Trim.Length > 0 Then
- 3 December, 2007 -- Original version posted