473,721 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(fi lespec, lines)
{
var fso = new ActiveXObject(" Scripting.FileS ystemObject");
var f = fso.OpenTextFil e(filespec, 1, false);
var saLines = new Array();
while (!f.AtEndOfStre am)
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\\shar e\\file.ext", 4) %></font></td></tr>
</table>

Aug 10 '05 #1
5 6194
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 RegularExpressi on, 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(fi lespec, lines)
{
var fso = new ActiveXObject(" Scripting.FileS *ystemObject");
var f = fso.OpenTextFil e(filespec, 1, false);
var saLines = new Array();
while (!f.AtEndOfStre am)
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
4898
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 with the following data : 1. Stijn Piot 58.12; 2. Kim Van Rooy 1.25; 3. Johnny Marcovich 2.37; 4. John Terlaeken (Bel) 1 ronde/tour; 5. Michael Bertrand 2.12;
1
2898
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 newString = ",a,b,c,"; var treeArray = newString.split(/\,/i); alert(treeArray.length);
3
3233
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 database or a Disconnected ADO Recordset since this is just passing data along to be written into an XML file... I've figured out how to split the data line by line by doing a
4
1324
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 there another option? thanks, Craig Buchanan
3
9667
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... field1...field2...field3...
5
5873
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() = Microsoft.VisualBasic.Strings.Split(aLine, vbNewLine, -1, CompareMethod.Binary)
7
2259
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 getting the results I expect. Dim SA as string() Dim S as string S="FBE"
2
2191
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 = "field != value" result = s1.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
12
3195
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(";"); MessageBox.Show(s);
14
1723
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 illogically? Here's a test I just put together that splits on "&". The test strings are: "a&b" = (Correct!) I expect array length 2 and I get 2 "a&" = (Incorrect!) I expect array length 1 but I get 2 "a" = (Correct!) I expect array length 1 and...
0
8852
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9227
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9081
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6676
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5992
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4761
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2143
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.