473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

how to read the last numeric number on the line?

dav
HI,

I am new to vb.net and i want to open a batch file to read the last
numeric number of each line and use that number (1/0) to determine if a
particular item of drop down box should be visible.

Can anyone help me with this?

Tahnks in advance.

Nov 21 '05 #1
3 1245
Dav,

Probably is your only solution in that Regex.

RegexLib
http://www.regexlib.com/Default.aspx

Expresso
http://www.ultrapico.com/Expresso.htm

I hope this helps a little bit?

Cor
Nov 21 '05 #2
dav
Managed to get what to display in a pretty bad manner... Look for a
better way to code it..
===================================
'Need to add 2 lines below if using streamreader!
'Please look at Mybase.load for more detail.
'line before Private Sub Fullbkup_Load are omitted
Imports System
Imports System.IO
Public Class Fullbkup
Inherits System.Windows.Forms.Form

'Basically just need to add lines below under mybase.load
Private Sub Fullbkup_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim sr As StreamReader = New StreamReader("C:\Documents and
Settings\davidfeng\Desktop\WSH\bat\dump_flag.bat")
Dim mystr As String
Do While sr.Peek() >= 0
mystr = sr.ReadLine
mystr = mystr.TrimEnd(" ")

If mystr = "SET /A HD1_archive=1" Then
mystr = "[HD1] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If

If mystr = "SET /A HD2_archive=1" Then
mystr = "[HD2] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If
If mystr = "SET /A HD3_archive=1" Then
mystr = "[HD3] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If

Loop
End Sub
End Class

Nov 21 '05 #3
Why not just use the substring method after you read the line into a string
variable?

mystr.Substring(mystr.Length - 1, 1) should get you the last character in
the line (after you have trimmed the trailling spaces of course).

then just check the value to see whether it is a 1 or a 2.

You can use the same method to get the other pieces of the line.

mystr = "SET /A HD1_archive=1"
mystr.Substring(0, 3) = "SET"
mystr.Substring(4, 2) = "/A"
mystr.Substring(7, 3) = "HD1"

Of course, if you can have variable lengths for the values above (maybe
"/A/B"place of "/A") then substring would only work if you based your
starting and ending points around the next space or =, etc. Fixed length or
delimited files make this easier, and XML really is the way to go if you
have the option, as you dont have to deal with subtrings at all. I suspect
that you are inheriting some interface file and that you are stuck with the
format, so substring is probably what you want to use.
"dav" <pd*****@yahoo.com.tw> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Managed to get what to display in a pretty bad manner... Look for a
better way to code it..
===================================
'Need to add 2 lines below if using streamreader!
'Please look at Mybase.load for more detail.
'line before Private Sub Fullbkup_Load are omitted
Imports System
Imports System.IO
Public Class Fullbkup
Inherits System.Windows.Forms.Form

'Basically just need to add lines below under mybase.load
Private Sub Fullbkup_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim sr As StreamReader = New StreamReader("C:\Documents and
Settings\davidfeng\Desktop\WSH\bat\dump_flag.bat")
Dim mystr As String
Do While sr.Peek() >= 0
mystr = sr.ReadLine
mystr = mystr.TrimEnd(" ")

If mystr = "SET /A HD1_archive=1" Then
mystr = "[HD1] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If

If mystr = "SET /A HD2_archive=1" Then
mystr = "[HD2] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If
If mystr = "SET /A HD3_archive=1" Then
mystr = "[HD3] requires file dump"
Me.ListBox1.Items.Add(mystr)
End If

Loop
End Sub
End Class

Nov 21 '05 #4

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

Similar topics

6
by: sea | last post by:
I have text files in the following format: 123,34, ,345,890, 123,23 .. .. .. As you can see, the problem is that (1) the commas can occur in
11
by: Sebastian Krause | last post by:
Hello, I tried to read in some large ascii files (200MB-2GB) in Python using scipy.io.read_array, but it did not work as I expected. The whole idea was to find a fast Python routine to read in...
2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
13
by: Don Kim | last post by:
I'm writing a program to read 2,000,000 floating point numbers off a text file, to compute the sum, mean, and median. This is a direct example of Stroustrup's paper. But the program will not...
35
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt",...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
23
by: ShaneO | last post by:
Hello, I wish to extract embedded string data from a file using a Binary Read method. The following code sample is used in VB.NET and similar code is used in VB6 - (Assume variable...
15
by: waltbrad | last post by:
Hello. I'm studying the book "C++ Primer Plus" by Stephan Prata. In chapter 6 he gives an exercise that reads from a file. The list is thus: 4 Sam Stone 2000 Freida Flass 100500 Tammy...
20
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.