Hi guys,
i want to add a character to the begining and the end of a multilne text box and save it into a file. e.g
1234
6789
9087
output
'1234',
'6789',
'9087'
i will appreciate the code to achieve this in vb6
Hi guys,
i want to add a character to the begining and the end of a multilne text box and save it into a file. e.g
1234
6789
9087
output
'1234',
'6789',
'9087'
i will appreciate the code to achieve this in vb6
This thread asked how to wrap each line of a multiline TextBox with single quotes and a comma and then save it to a file. gave the common Split+loop approach and pointed out adding the trailing comma. Below are a compact alternative and a few practical notes that help for real-world input (blank lines, embedded quotes, different line endings, encoding).
A one-pass way in VB6 is to use VBScript RegExp (add reference to "Microsoft VBScript Regular Expressions 5.5") to replace each non-empty line with a quoted, comma-terminated line:
' Reference Microsoft VBScript Regular Expressions 5.5
Dim re As RegExp
Set re = New RegExp
re.Pattern = "^\s*(.+)\s*$"
re.Global = True
re.MultiLine = True
Dim inputText As String
' populate inputText from textbox or file
Dim outText As String
outText = re.Replace(inputText, "'$1',") Notes and tips:
These additions handle common edge cases while keeping the per-line transformation concise.
Jump to Post— selvaganapathy 31Hi,
U can do parse the Text first, then apply single quotesTo Parse
Dim MyArr MyArr = Split (Text1.Text, vbCrLF)Iterate through loop and add single quotes
Dim i as Integer Dim newString as String For i = 0 To UBound(MyArr) newString …
Hi,
U can do parse the Text first, then apply single quotes
To Parse
Dim MyArr
MyArr = Split (Text1.Text, vbCrLF) Iterate through loop and add single quotes
Dim i as Integer
Dim newString as String
For i = 0 To UBound(MyArr)
newString = newString & "'" & MyArr(i) & "'" & vbCrLf
Next
Text1.Text = newString great code.
just to correct ;)
newString = newString & "'" & MyArr(i) & "'," & vbCrLf Hi Jx_Man,
Thanks
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.