473,574 Members | 2,498 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?



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>

Aug 10 '05 #1
5 6191
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?



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++)
for (var j=0; j<c.length; j++)
s+="<td><font size=1 face=arial>";
return s;

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

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

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

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...
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);
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...
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
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...
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)
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"
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);
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);
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...
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...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
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. ...
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...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.