Xojo Conferences
MBSOct2019CologneDE

Parsing text file (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: [OOPS] Re: Parsing text file
Next thread: control dragging


Localized strings in tabpanel   -   Jan Erik Moström <
  Parsing text file   -   Mike Tuller
   Re: Parsing text file   -   Hasan Edain
   Re: Parsing text file   -   Tyson Tate
    Re: Parsing text file   -   Kevin Ballard
   Re: Parsing text file   -   Mike Tuller
   [OOPS] Re: Parsing text file   -   Tyson Tate

Parsing text file
Date: 31.05.02 19:38 (Fri, 31 May 2002 13:38:35 -0500)
From: Mike Tuller
I am wanting to pull specific information out of the /etc/hostconfig file.
Specifically the Appletalk Hostname. How do I specify that I want to pull
data from that line only, and that all I want is the name, not the whole
line. I already have it so that it can pull all of the info, I just need to
know how to narrow it down to only the info I need.

So in the hostconfig it has:

AFPSERVER=-NO-
APPLETALKà0
AUTHSERVER=-NO-
AUTOMOUNT=-YES-
CONFIGSERVER=-NO-
IPFORWARDING=-NO-
MAILSERVER=-NO-
MANAGEMENTSERVER=-NO-
NETINFOSERVER=-AUTOMATIC-
RPCSERVER=-AUTOMATIC-
NETBOOTSERVER=-NO-
NISDOMAIN=-NO-
TIMESYNC=-YES-
QTSSERVER=-NO-
SSHSERVER=-YES-
WEBSERVER=-NO-
SAMBA=-YES-
APPLETALK_HOSTNAME="Mike Tuller? Computer"

I want to return "Mike Tuller's Computer"

Thanks for the help.

Mike

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Parsing text file
Date: 31.05.02 19:54 (Fri, 31 May 2002 11:54:30 -0700)
From: Hasan Edain
So this may be overkill, but I love to use a Dictionary here.

Read the entire file in a line at a time.

for each line split the line on the '=' character.
(nthWord will do it, as will a number of other strategies)

then when you have the two sides of the equal, put the left side as a key,
and the right side as the value in a dictionary.

then you can use dictionary.hasKey to see if this conf has the line you
are looking for.
and dictionary.value to get the value you need.

Hope this helps.

Hasan

On Friday, May 31, 2002, at 11:38 AM, Mike Tuller wrote:

> I am wanting to pull specific information out of the /etc/hostconfig file.
> Specifically the Appletalk Hostname. How do I specify that I want to pull
> data from that line only, and that all I want is the name, not the whole
> line. I already have it so that it can pull all of the info, I just need
> to
> know how to narrow it down to only the info I need.
>
> So in the hostconfig it has:
>
> AFPSERVER=-NO-
> APPLETALKà0
> AUTHSERVER=-NO-
> AUTOMOUNT=-YES-
> CONFIGSERVER=-NO-
> IPFORWARDING=-NO-
> MAILSERVER=-NO-
> MANAGEMENTSERVER=-NO-
> NETINFOSERVER=-AUTOMATIC-
> RPCSERVER=-AUTOMATIC-
> NETBOOTSERVER=-NO-
> NISDOMAIN=-NO-
> TIMESYNC=-YES-
> QTSSERVER=-NO-
> SSHSERVER=-YES-
> WEBSERVER=-NO-
> SAMBA=-YES-
> APPLETALK_HOSTNAME="Mike Tuller? Computer"
>
> I want to return "Mike Tuller's Computer"
>
> Thanks for the help.
>
> Mike
>
> ---
> Subscribe to the digest:
> <mailto:<email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>
Hasan Edain
<email address removed>
"Minds are like parachutes, they only function when open"

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Parsing text file
Date: 31.05.02 20:19 (Fri, 31 May 2002 12:19:39 -0700)
From: Tyson Tate
The cheap easy hack way would be:

Parse(s as string) as string
Begin sub
return replaceall(nthfield(s, "APPLETALK_HOSTNAME=", 2), chr(34), "")
End sub

-Tyson

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Parsing text file
Date: 31.05.02 20:26 (Fri, 31 May 2002 15:26:10 -0400)
From: Kevin Ballard
On 5/31/02 3:19 PM, "Tyson Tate" <<email address removed>> wrote:

> The cheap easy hack way would be:
>
> Parse(s as string) as string
> Begin sub
> return replaceall(nthfield(s, "APPLETALK_HOSTNAME=", 2), chr(34), "")
> End sub

Ugly, and what if there's other parameters after APPLETALK_HOSTNAME?

I guess you could use the even uglier hack:

Function Parse(s As String) As String
Return ReplaceAll(NthField(NthField(s, "APPLETALK_HOSTNAME=", 2),
chr(34), ""), 1, Chr(13))
End Function

(unless it uses Chr(10) as linebreaks...)

But, like I said, that's really ugly. I like the dictionary idea. As an
alternate, you could read each line and check if the first 18 chars is
"APPLETALK_HOSTNAME", and if it is then grab everything from 21 to length-1
(to get rid of quotes). But that's also kinda ugly. Dictionary is cleanest.

Re: Parsing text file
Date: 31.05.02 20:20 (Fri, 31 May 2002 14:20:31 -0500)
From: Mike Tuller
That's what I was looking for. Thanks!

> From: Jason Brown <<email address removed>>
> Date: Fri, 31 May 2002 12:05:40 -0700
> To: Mike Tuller <<email address removed>>
> Subject: RE: Parsing text file
>
> Dim theTempString as string
> Dim theFoundAT as boolean
> Dim theAppletalkname as string
>
> theFoundAT = false
> while not textinputstream.eof
>
> theTempString = textinputstream.readline
>
> if instr(theTempString,"APPLETALK_HOSTNAME") > 0 then
> theAppletalkname = nthField(theTempString,"=",2)
> theAppletalkname = left(theAppletalkname,len(theAppletalkname)-1)
> theAppletalkname = right(theAppletalkname,len(theAppletalkname)-1)
> theFoundAT = true
> end if
>
> wend
>
> if theFoundAT = true then
>
> msgbox theAppletalkname + " is the name of this appletalk enabled computer?"
>
> else
>
> msgbox "Appletalk is not active or something like this"
>
> end if

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>