472,802 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,802 software developers and data experts.

how to split an array?

i have a function (below) which reads the last n lines from a text
file. rather than read the whole line and output it as is, i want to be
able to read the line and split the tab delimited text file so I can
present it in columns, exclude unwanted data etc. can anyone help me
rewrite the javascript function to achieve this?

thx

Chris

function GetLastLines(filespec, lines)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filespec, 1, false);
var saLines = new Array();
while (!f.AtEndOfStream)
saLines[saLines.length] = f.ReadLine();
f.Close( );

var s = "";

for (var i = saLines.length - lines; i < saLines.length; i++)
s += saLines[i] + "<br />";

return s;
}
*** SNIP ***

<table border=0 cellpadding=0 cellspacing=0>
<tr><td><font size=1 face=arial>
<%= GetLastLines("\\\\server\\share\\file.ext", 4) %></font></td></tr>
</table>

Aug 10 '05 #1
5 6148
Have a look at the Array.split(arg) method.

"arg" specifies the character or characters where the split will occur.

"arg" can either be-

a string, e.g. split("\t")

a RegularExpression, e.g. split(/\t+/)

Aug 10 '05 #2
i've read it several times, but i'm not a programmer so i don't really
understand it. can you help me rewrite the code so it works?

thanks

Chris

Aug 10 '05 #3
I have limited time, so the most I can offer is the following, but it
is rough. Ultimately if you are not a programmer, how will you be able
to understand/maintain any suggestion you are given?

Quick option 1

Put the lines in a <PRE> element to preserve the existing tabs.

Option 2 - table format

What table format do you really want?

Try the following, untested, rough, not guaranteed in any way:-

function GetLastLines(filespec, lines)
{
var fso = new ActiveXObject("Scripting.FileS*ystemObject");
var f = fso.OpenTextFile(filespec, 1, false);
var saLines = new Array();
while (!f.AtEndOfStream)
saLines[saLines.length] = f.ReadLine();
f.Close( );

var s = "";
var c;
for (var i = saLines.length - lines; i < saLines.length; i++)
{
s+="<tr>";
c=saLines[i].split(/\t+/);
for (var j=0; j<c.length; j++)
{
s+="<td><font size=1 face=arial>";
s+=c[j];
s+="</font></td>";
}
s+="</tr>";
}
return s;
}

*** SNIP ***
<table border=0 cellpadding=0 cellspacing=0><tbody>

<%= GetLastLines("\\\\server\\shar*e\\file.ext", 4) %>
</tbody></table>

Aug 10 '05 #4
you're right.. i cannot understand or maintain it myself - perhaps it
is a pointless exercise. thanks for taking the time to reply and to
help.. it is very much appreciated.

Aug 11 '05 #5
Glad to offer help. Didn't mean to be too abrupt. :-)

Aug 11 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nieuws | last post by:
Hi, I was trying to do the following. It's my first php "project", so it's quiet logic that i have some problems. Perhaps the php community might help. It's about this : I have a txt file...
1
by: jhcorey | last post by:
I don't know where the actual issue is, but hopefully someone can explain. The following displays "5" in FireFox, but "3" in IE: <script type="text/javascript" language="javascript"> var...
3
by: Jan Hanssen | last post by:
Hi! I have a list of data in a textfile which is tab delimited. Each line is seperated by a VbCrLf. I want to collect this data in a multidimensional string array. I do not wish to use a...
4
by: Craig Buchanan | last post by:
I am trying to split a comma-delimited string into a string array. unfortunately, if the string doesn't contain a comma, the resulting array is Nothing. other than using vb6 compatibility, is...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
2
by: Digital Fart | last post by:
following code would split a string "a != b" into 2 strings "a" and "b". but is there a way to know what seperator was used? string charSeparators = { "=", ">=", "<=" , "!=" }; string s1 =...
12
by: garyusenet | last post by:
string lines = File.ReadAllLines(@"c:\text\history.txt"); foreach (string s in lines) { ArrayList results = new ArrayList(); string delimit = ";"; string currentline = s.Split(";"); ...
14
by: Stevo | last post by:
If you split a string into an array using the split method, it's not working the way I'd expect it to. That doesn't mean it's wrong of course, but would anyone else agree it's working somewhat...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.