Link to home
Start Free TrialLog in
Avatar of tjgrindsted
tjgrindsted

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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--%
Avatar of Bill Prew
Bill Prew

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
Avatar of tjgrindsted

ASKER

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

need to edit a little in it, but after that it worked fine.