|
-
Jul 12th, 2010, 12:31 PM
#1
Thread Starter
Lively Member
Simple question
hi all,
Need something pretty urgently....
how can i dump a small html code in a variable ? do i need to take array ?
i need to write below line to a file "as is"
Code:
$a = "<style>"
$a = $a + "BODY{background-color:skyblue;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"
how can i make VB turn off recognition of it's operative characters like $,<,>,= etc. which appears on above code but i need to dump it "as it is" in a file during runtime.
pls help...
-
Jul 12th, 2010, 01:56 PM
#2
Member
Re: Simple question
Code:
Dim a As String = "<style>"
a += "BODY{background-color:skyblue;}"
a += "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
a += "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
a += "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
a += "</style>"
-
Jul 13th, 2010, 02:58 AM
#3
Thread Starter
Lively Member
Re: Simple question
 Originally Posted by Royal
Code:
Dim a As String = "<style>"
a += "BODY{background-color:skyblue;}"
a += "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
a += "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
a += "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
a += "</style>"
appreciate the reply but that's not precisely what i want...
for eg. i initialized a string StrData then i want StrData to store the entire code written in my first post & then finally dump that into a text file
for eg :
Code:
Dim StrData as String
StrData = "$a = "<style>""
StrData += "$a = $a + "BODY{background-color:skyblue;}""
....
....
so what i want is that string should save $ , = etc as a "string" data & NOT as a operator
-
Jul 13th, 2010, 06:55 AM
#4
Thread Starter
Lively Member
Re: Simple question
guys pls...there shud be something to resolve this ....
-
Jul 13th, 2010, 07:18 AM
#5
Re: Simple question
Technically, if it is wrapped in quotation marks, it will be taken literally. What's wrong with the example code you put, excluding the fact that you've forgotten to add Environment.NewLine() behind each of your lines.
-
Jul 13th, 2010, 11:03 AM
#6
Thread Starter
Lively Member
Re: Simple question
 Originally Posted by MaximilianMayrhofer
Technically, if it is wrapped in quotation marks, it will be taken literally. What's wrong with the example code you put, excluding the fact that you've forgotten to add Environment.NewLine() behind each of your lines.
vb does not take my code as is , it gives me syntax error & stuff ahead of either "=" or "$" or "< , >"
-
Jul 13th, 2010, 11:15 AM
#7
Re: Simple question
If you have a literal " in your string, you have to escape it with another ". Simple as that.
So let's say you have this string
Code:
$a = $a + "BODY{background-color:skyblue;}"
And you want to assign it to a string variable, you have to enclose that string in " to tell the compiler that this is a string, and then you escape any literal " that you have in that string. So the code will look like this:
Code:
Dim myString As String = "$a = $a + ""BODY{background-color:skyblue;}"""
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 13th, 2010, 11:18 AM
#8
Re: Simple question
This works for me:
Code:
Dim a As String = "<style>" & System.Environment.NewLine
a &= "BODY{background-color:skyblue;}" & System.Environment.NewLine
a &= "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" & System.Environment.NewLine
a &= "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" & System.Environment.NewLine
a &= "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}" & System.Environment.NewLine
a &= "</style>"
MsgBox(a)
To write it to a file you use a streamwriter next.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jul 13th, 2010, 11:25 AM
#9
Re: Simple question
 Originally Posted by GaryMazzone
This works for me:
Code:
Dim a As String = "<style>" & System.Environment.NewLine
a &= "BODY{background-color:skyblue;}" & System.Environment.NewLine
a &= "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" & System.Environment.NewLine
a &= "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" & System.Environment.NewLine
a &= "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}" & System.Environment.NewLine
a &= "</style>"
MsgBox(a)
To write it to a file you use a streamwriter next.
Yes, it works (syntax wise) but you're also changing the string. For example, the " in the string "BODY{background-color:skyblue;}" are part of the data and they need to be preserved. However, you just dropped them completely.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 13th, 2010, 11:29 AM
#10
Re: Simple question
Stan I don't think so. I copied the supplied code and use it. The BODY{background-color:skyblue}; is still in the string that is generated. I really have absolutely no idea what the OP is actually trying to do since the question appears to have changed in the middle of the thread.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jul 13th, 2010, 03:41 PM
#11
Re: Simple question
Gary, I beleive the OP is trying to do some kind of php code generator from this line in post #1
Code:
i need to write below line to a file "as is"
If you look at the code section in his initial post, what he wants is to assign everything in that section to a string variable so that he can write it out to a .php file. The code you provided is more like converting his php code to vb.net code.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 15th, 2010, 01:36 PM
#12
Thread Starter
Lively Member
Re: Simple question
Finally !!!
after a few trial & error was able to achieve wht i wanted here's what i did :
Code:
Dim TableFrmt As String = "$a= " & Chr(34) & "<style>" & Chr(34) & System.Environment.NewLine
TableFrmt &= "$a = $a + " & Chr(34) & "BODY{background-color:skyblue;}" & Chr(34) & System.Environment.NewLine
TableFrmt &= "$a = $a + " & Chr(34) & "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" & Chr(34) & System.Environment.NewLine
TableFrmt &= "$a = $a + " & Chr(34) & "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" & Chr(34) & System.Environment.NewLine
TableFrmt &= "$a = $a + " & Chr(34) & "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}" & Chr(34) & System.Environment.NewLine
TableFrmt &= "$a = $a + " & Chr(34) & "</style>" & Chr(34) & System.Environment.NewLine
TableFrmt &= System.Environment.NewLine
chr(34) is for retaining double quotes "as is" like i said in my 1st post
thx every1 for help
-
Jul 16th, 2010, 10:49 AM
#13
Re: Simple question
If you follow these VB rules for string then it become very simple to do what you need:
1. All literal strings need to be enclosed with double quotes.
2. A literal double quote has to be escaped with another literal double quote.
So let's do an example by taking your original data and assign it to a string variable.
First you just declare a string variable and assign an empty string to it.
Code:
Dim myString as String = ""
Now you copy the first line of the string data and paste it in between the quotes (rule #1), then add another double quote right to front of each and every double quote you see in the string except the 2 at the very ends of the string. It then becomes:
Code:
Dim myString as String = "$a = ""<style>"""
Now if you want to add another line to this string, you append a newline character to it, and for readability, you may also using the VB line continuation but it's not required.
Code:
Dim myString as String = "$a = ""<style>""" & Environment.NewLine & _
Start a new line with an empty string again and paste in the 2nd line, escape the quotes... Just repeat the steps until you're done with all the lines.
Code:
Dim myString as String = "$a = ""<style>""" & Environment.NewLine & _
"$a = $a + ""BODY{background-color:skyblue;}""" & Environment.NewLine & _
"a += '"TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}'"" & Environment.NewLine & _
"a += '"TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}'"" & Environment.NewLine & _
"$a = $a + '"TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}'"" & Environment.NewLine & _
"$a = $a + '"</style>'""
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|