how do i split a string, with two split request !?

Hi
if i have this text (maybe with some other separators)

tester;; test; test2; tester5;; test4;

how can i then split this string, so if two ;; then i get UPPER letters and if only one ; then just get the text as it is, and put the data into a response.write so i get this output:

TESTER
test
test2
TESTER5
test4
tjgrindstedAsked:
Who is Participating?
 
RobSampsonCommented:
Hi, something like this should work.

Regards,

Rob.
mystring = "tester;; test; test2; tester5;; test4;"
arrSplit1 = Split(mystring, ";;")
For Each strBit1 In arrSplit1
	arrSplit2 = Split(strBit1, ";")
	For intBit2 = LBound(arrSplit2) To UBound(arrSplit2)
		If intBit2 = UBound(arrSplit2) Then
			WScript.Echo Trim(UCase(arrSplit2(intBit2)))
		Else
			WScript.Echo Trim(arrSplit2(intBit2))
		End If
	Next
Next

Open in new window

0
 
Randy DownsOWNERCommented:
Maybe this will help. You just need to change the delimiter

textdelimiter = ";"


http://www.theukwebdesigncompany.com/articles/article.php?article=151

<%--
Beginning of script Reading a delimited text file written by G.Ajaykumar<ajaykumar_g@hotmail.com>--%>

<%@Import Namespace="System.IO"%>
<script language="vb" runat="server">
Sub page_load(Sender As Object,e As EventArgs)
Dim filetoread as string
filetoread=server.mappath("readtest.txt")
dim filestream as StreamReader
filestream = File.Opentext(filetoread)
Dim readcontents as String
readcontents = fileStream.ReadToEnd()
Dim textdelimiter as String
textdelimiter = ","
Dim splitout = Split(readcontents, textdelimiter)
lblplaintext.text = readcontents & "<br>"
dim i as integer
for i=0 to Ubound(splitout)
lblsplittext.Text &= "<b>Split </b>" & i+1 & ") " & splitout(i)& "<br>"
next
filestream.Close()
End Sub
</script>
<asp:label align="center" ForeColor="Maroon" Font-Names="Arial" BackColor="LemonChiffon" BorderColor="#0000C0" runat="server" id="lbldisplay" Font-Name="Verdana" text="Reading a delimited text file using ASP.NET/VB.NET coded by G.Ajaykumar" /><br />
<br /><br /><b>Plain Output</b><br />
<asp:label runat="server" id="lblplaintext" Font-Name="Verdana" /><br />
<b>Split Output</b><br />

<asp:label runat="server" id="lblsplittext" Font-Name="Verdana" />
<%-- End of script--%
0
 
Bill PrewCommented:
Here's a small code snipit that might give you a starting place, I coded as a stand alone VBS just for some testing.

strInput = "tester;; test; test2; tester5;; test4;"

arrInput = Split(strInput, ";")
intMax = UBound(arrInput) - 1

i = 0
While i <= intMax
   n = 1
   If i < intMax Then
      If arrInput(i + 1) = "" Then
         arrInput(i) = UCase(arrInput(i))
         n = 2
      End If
   End If
   WScript.Echo Trim(arrInput(i))
   i = i + n
Wend

Open in new window

~bp
0
 
tjgrindstedAuthor Commented:
Hi all thx.

RodSampson
I used ur code, it works fine after edit a little in it, but thx.
The code is
    Sub input()
        Dim mystring As String = "tester;; test; test2; tester5;; test4;"
        Dim arrSplit1 As String() = Split(mystring, ";;")
        For Each strBit1 In arrSplit1
            Dim arrSplit2 As String() = Split(strBit1, ";")
            For intBit2 = LBound(arrSplit2) To UBound(arrSplit2)
                If intBit2 = UBound(arrSplit2) Then
                    Response.Write(Trim(UCase(arrSplit2(intBit2))) & "<br />")
                Else
                    Response.Write(Trim(arrSplit2(intBit2)) & "<br />")
                End If
            Next
        Next
    End Sub

Open in new window

0
 
tjgrindstedAuthor Commented:
need to edit a little in it, but after that it worked fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.