Need to open and read text file.
Moderator: Rathinagiri
Re: Need to open and read text file.
Found this to parse delimited text to an array. Looks good.
https://www.tek-tips.com/viewthread.cfm?qid=87443
I think I have about all the stuff I need for now.
Thanks Guys!
https://www.tek-tips.com/viewthread.cfm?qid=87443
I think I have about all the stuff I need for now.
Thanks Guys!
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Need to open and read text file.
Code: Select all
HB_ATokens()
Splits a string into tokens based on a delimiter.
Syntax
HB_ATokens( <cString> , ;
[<cDelimiter>] , ;
[<lSkipQuotes>] , ;
[<lDoubleQuotesOnly>] ) --> aTokens
Arguments
<cString>
This is a character string which is tokenized based on the value of <cDelimiter>.
<cDelimiter>
A single character can be specified as delimiter used to tokenize the string <cString>. It defaults to a blank space (Chr(32)).
<lSkipQuotes>
This parameter defaults to .F. (false). When it is set to .T. (true), all portions of <cString> enclosed in single or double quotes are not searched for <cDelimiter>.
<lDoubleQuoteOnly>
The parameter is only relevant when <lSkipQuotes> is .T. (true). When <lDoubleQuoteOnly> is also .T. (true), only portion sof <cString> enclosed in double quotes are not searched for <cDelimiter>. Return
The function returns an array of character strings.
Description
HB_ATokens() function splits <cString> into substrings, based on the value of <cDelimiter>. The delimiter is removed from <cString> and the resulting substrings are collected in an array, which is returned.
If <lSkipQuotes> is .T. (true), a quoted substring within <cString> is not split if it contains the delimiter sign. If the value of <lSkipQuotes> is .F. (false), which is the default, the quoted substring will be split, regardless of the quotes. The <lDoubleQuoteOnly> argument specifies if both the double and single quote signs are interpreted as a quote sign (.F.) or only the double quote is recognized as a quote sign (.T.).
Info
See also: At(), AtToken(), IN, Left(), Rat(), Right(), SubStr()
Category: Array functions , Character functions , Token functions
Source: vm\arrayshb.c
Example
// The example displays the result of HB_ATokens() using different
// combinations for <lSkipQuotes> and <lDoubleQuoteOnly>
PROCEDURE Main
LOCAL cString := [This\'_is\'_a_tok"e_n"ized_string]
LOCAL aTokens := {}
LOCAL i
aTokens := HB_ATokens( cString, "_", .F., .F. )
FOR i := 1 TO Len( aTokens )
? aTokens[i]
NEXT
// Result: array with 6 elements
// This\'
// is\'
// a
// tok"e
// n"ized
// string
aTokens := HB_ATokens( cString, "_", .T., .F. )
FOR i := 1 TO Len( aTokens )
? aTokens[i]
NEXT
// Result: array with 4 elements
// This\'_is\'
// a
// tok"e_n"ized
// string
aTokens := HB_ATokens( cString, "_", .T., .T. )
FOR i := 1 TO Len( aTokens )
? aTokens[i]
NEXT
// Result: array with 5 elements
// This\'
// is\'
// a
// tok"e_n"ized
// string
RETURN
Viva INTERNATIONAL HMG 
Re: Need to open and read text file.
Neat!
I have enough code to tweak into what I need. Really love the Forum and all the expert advice.
I have enough code to tweak into what I need. Really love the Forum and all the expert advice.
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Need to open and read text file.
Dear Claudio, may you accept a suggestion in order to take place TITLE for msgbox (at first parameter as optional) in your very usefull MsgDebug function ?srvet_claudio wrote:Since version HMG.3.1.3
Code: Select all
MsgDebug ( xData1, xData2, ... ) --> Accepts as a parameters any data type, elements or objects. Returns a string with the message displayed on the screen. Example: Num := 10 aData := { "Number", 38, "aRGB", YELLOW, "Hello" } cMsg := MsgDebug ( TIME(), aData, {|| NIL}, Num == 3 )
Please note this code:
Code: Select all
Function MsgDebug
Local i, cMsg, nParam:=PCount(), nStart:=1, cTit:="DEBUG INFO"
If nParam>1 .and. ValType(PValue(1))="C"
nStart:=2
cTit:=PValue(1)
Endif
cMsg := "Called from: " + ProcName(1) + "(" + LTrim(Str(ProcLine(1))) + ") --> " + ProcFile(1) + CRLF + CRLF
For i = nStart To nParam
cMsg := cMsg + hb_ValToExp(PValue(i)) + IIf (i < nParam, ", ", "")
Next
MsgBox(cMsg, cTit)
Return cMsgWhat do you think, Claudio ? Can it be adopted this change in MsgDebug ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Re: Need to open and read text file.
I also suggest for change for title as first parameter as title of MsgDebug
Further MsgDebug to be renamed to DebugInfo ?
Further MsgDebug to be renamed to DebugInfo ?
BPD
Convert Dream into Reality through HMG
Convert Dream into Reality through HMG
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Need to open and read text file.
Thanks Dave for your interest.bpd2000 wrote:I also suggest for change for title as first parameter as title of MsgDebug
Ohhh no... both functions must be separated as different modes. Also note I suggest to replace MsgInfo fo MsgBox at MsgDebug function.Further MsgDebug to be renamed to DebugInfo ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- srvet_claudio
- Posts: 2224
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: Need to open and read text file.
Hi Pablo.Pablo César wrote: This would accepts the first parameter as title of MsgDebug and will works as optional. And also change MsgInfo by MsgBox (without any Icon, my opinion)
What do you think, Claudio ? Can it be adopted this change in MsgDebug ?
Change MsgInfo by MsgBox: it's good idea.
First parameter as title: I believe that this is not the best solution because MsgDebug is a function for use internal and fast and easy, without having to think about the type or the order of the parameters.
Maybe with some global variable could be arranged with use of the #translate, e.g.
MSGDEBUG [ TITLE cTitle ] [ PARAMETERS ] par1, par2, ... , parN [STOREIN cMsg]
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Re: Need to open and read text file.
Better idea !! Thanks Claudio !srvet_claudio wrote:Maybe with some global variable could be arranged with use of the #translate, e.g.
MSGDEBUG [ TITLE cTitle ] [ PARAMETERS ] par1, par2, ... , parN [STOREIN cMsg]
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Need to open and read text file.
Dear Claudio,
I have make many test with long strings and as always I do, I use your blessed function MsgDebug. But sometimes, strings and arrays are so long that I can not visualize all items completly.
Is it possible to add a kind of EditBox (but not editable) with scrollbars, so you can scroll the screen and also would select some text on the screen ?. That would help a lot.
I saw something similar at "Build log" button of current IDE. Leveraging the subject: I noted that EditBox is allowing to edit text of log. Is this was supposed to work like this ?
Thanks for your attention, once again !
I have make many test with long strings and as always I do, I use your blessed function MsgDebug. But sometimes, strings and arrays are so long that I can not visualize all items completly.
Is it possible to add a kind of EditBox (but not editable) with scrollbars, so you can scroll the screen and also would select some text on the screen ?. That would help a lot.
I saw something similar at "Build log" button of current IDE. Leveraging the subject: I noted that EditBox is allowing to edit text of log. Is this was supposed to work like this ?
Thanks for your attention, once again !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
- srvet_claudio
- Posts: 2224
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: Need to open and read text file.
It is a good idea.Pablo César wrote:Dear Claudio,
I have make many test with long strings and as always I do, I use your blessed function MsgDebug. But sometimes, strings and arrays are so long that I can not visualize all items completly.
Is it possible to add a kind of EditBox (but not editable) with scrollbars, so you can scroll the screen and also would select some text on the screen ?. That would help a lot.
I saw something similar at "Build log" button of current IDE. Leveraging the subject: I noted that EditBox is allowing to edit text of log. Is this was supposed to work like this ?
Thanks for your attention, once again !