ASP Help Needed

Thorondorito

One of Freddy's beloved
Joined
Jan 4, 2004
Messages
498
Hi guys.

Im developing some intranet app and I need to parse a string into an array in ASP.

For example, given the following string:

"wpeoriuweporwwlrjwelkj werujwpejrwe werjwejrwpr weporuweporuw
wperiwpoeriw priwporiweporiw rwpoirwpoe rwporiw rwporiwpoeri wep
wperoiweporiw rpwirwpoidslalsdm asmda,s.dmqpwmd dpqklwdñq wl
qpowdqpowid qwpoidqpowiqpo dqpowidopqwid qwpodiqw pdiqwpodi
blablablabla blablablablablablablabla blablablablablablablabla"

What I need is an array containing 1 line for each string line (\n). Is it possible in ASP?

Thanks in advance!
 

scarloc

Fledgling Freddie
Joined
Dec 29, 2003
Messages
567
use perl and its a piece of piss, one line of code should do it.


how are you receiving the info you need to parse? what format do you want the output in?
 

DocWolfe

Part of the furniture
Joined
Jan 3, 2005
Messages
2,855
I havent used asp for ages but it definately is possible.

Code:
Dim arrayLines, oneLine, originalString

originalString = "wpeoriuweporwwlrjwelkj werujwpejrwe werjwejrwpr weporuweporuw\n
wperiwpoeriw priwporiweporiw rwpoirwpoe rwporiw rwporiwpoeri wep\n
wperoiweporiw rpwirwpoidslalsdm asmda,s.dmqpwmd dpqklwdñq wl\n
qpowdqpowid qwpoidqpowiqpo dqpowidopqwid qwpodiqw pdiqwpodi\n
blablablabla blablablablablablablabla blablablablablablablabla"

arrayLines = Split(originalString, "\n", -1, 1)

For Each oneLine in arrayLines
  Response.Write(oneLine)
  Response.Write("<br>")
Next

That should work... I'll test it in a min and get back to you :p
 

DocWolfe

Part of the furniture
Joined
Jan 3, 2005
Messages
2,855
cant remember what the newline character is in asp... :( but that works you just need to find out what the character is.
 

Gamah

Banned
Joined
Dec 22, 2003
Messages
13,042
DocWolfe said:
cant remember what the newline character is in asp... :( but that works you just need to find out what the character is.

its the visual basic line break afaik "vbCrLf"
 

Thorondorito

One of Freddy's beloved
Joined
Jan 4, 2004
Messages
498
DocWolfe said:
I havent used asp for ages but it definately is possible.

Code:
Dim arrayLines, oneLine, originalString

originalString = "wpeoriuweporwwlrjwelkj werujwpejrwe werjwejrwpr weporuweporuw\n
wperiwpoeriw priwporiweporiw rwpoirwpoe rwporiw rwporiwpoeri wep\n
wperoiweporiw rpwirwpoidslalsdm asmda,s.dmqpwmd dpqklwdñq wl\n
qpowdqpowid qwpoidqpowiqpo dqpowidopqwid qwpodiqw pdiqwpodi\n
blablablabla blablablablablablablabla blablablablablablablabla"

arrayLines = Split(originalString, "\n", -1, 1)

For Each oneLine in arrayLines
  Response.Write(oneLine)
  Response.Write("<br>")
Next

That should work... I'll test it in a min and get back to you :p

That's a nice aproximation. But I can't find the eof character in vbasic script.
Btw, the string is given from a form text field.

Thanks Doc.
 

DocWolfe

Part of the furniture
Joined
Jan 3, 2005
Messages
2,855
Thorondorito said:
That's a nice aproximation. But I can't find the eof character in vbasic script.
Btw, the string is given from a form text field.

Thanks Doc.

EOF are you trying to open a file now? :p

Here ya go; a form that when submitted puts each new line into an array and prints out each member of the array on a different line in html.

Code:
<% Option Explicit %>
<%
If Request.Form("text") <> "" then

  Dim arrayLines, oneLine, originalString

  originalString = Request.Form("text")
  Response.Write(originalString & "<br>")
  arrayLines = Split(originalString, vbCrLf, -1, 1)

  For Each oneLine in arrayLines
    Response.Write(oneLine)
    Response.Write("<br>")
  Next

Else
%>
<html>
  <form action="test2.asp" method="post">
    <textarea name="text"></textarea>
    <input type="submit" />
  </form>
</html>
<%
End If
%>

definately works ;)
 

Users who are viewing this thread

Top Bottom