• Converting array to string

    From rodrego sandino@21:1/5 to All on Tue Jun 29 08:57:01 2021
    Is there any way to convert an array to string where each element can be access directly like in MEMOREAD function when it reads file you can access each line in file easily by MEMOLINE function .

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rodrego sandino@21:1/5 to rodrego sandino on Tue Jun 29 12:26:35 2021
    On Tuesday, June 29, 2021 at 3:57:02 PM UTC, rodrego sandino wrote:
    Is there any way to convert an array to string where each element can be access directly like in MEMOREAD function when it reads file you can access each line in file easily by MEMOLINE function .
    to simplified my question i want to do the following :
    Create an empty String Buffer object.
    Traverse through the elements of the String array using loop.
    In the loop, append each element of the array to the StringBuffer object using the append() method.
    Finally convert the StringBuffer object to string using the toString() method. How i can do that in xharbour ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to sandin...@gmail.com on Tue Jun 29 14:53:41 2021
    Dear sandin...:

    On Tuesday, June 29, 2021 at 12:26:37 PM UTC-7, sandin...@gmail.com wrote:
    On Tuesday, June 29, 2021 at 3:57:02 PM UTC, rodrego sandino wrote:
    Is there any way to convert an array to string where each
    element can be access directly like in MEMOREAD function
    when it reads file you can access each line in file easily by
    MEMOLINE function .

    What do you know about the data type of the elements in the array? What do you know about the dimensonality of the arrays, as in how many parameters there are (uArray(1,2,3,4,5) := codestring)? If more than one dimension (row AND column), do you need
    to know "position"?

    I'd use this as a template: https://github.com/harbour/core/blob/master/tests/foreach.prg

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniele@21:1/5 to All on Wed Jun 30 09:12:31 2021
    Il 29/06/2021 17:57, rodrego sandino ha scritto:
    Is there any way to convert an array to string where each element can be access directly like in MEMOREAD function when it reads file you can access each line in file easily by MEMOLINE function .


    aStrings:={"one","two","three"}

    with a codeblock:

    cString:=""
    ascan(aStrings,{|x|cstring+=x+hb_eol()}) // hb_osNewLine in xHarbour
    ? cString

    or with a function:

    cString:=a2s(aStrings)
    ? CSTRING

    func a2s(aArr)
    local cRes:="",t
    for t:=1 to len(aArr)
    cRes=cRes+rtrim(aArr[t])+hb_eol() // hb_OsNewLine xHb","
    next t
    return cRes

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rodrego sandino@21:1/5 to Daniele on Wed Jun 30 13:29:05 2021
    On Wednesday, June 30, 2021 at 7:12:35 AM UTC, Daniele wrote:
    Il 29/06/2021 17:57, rodrego sandino ha scritto:
    Is there any way to convert an array to string where each element can be access directly like in MEMOREAD function when it reads file you can access each line in file easily by MEMOLINE function .

    aStrings:={"one","two","three"}

    with a codeblock:

    cString:=""
    ascan(aStrings,{|x|cstring+=x+hb_eol()}) // hb_osNewLine in xHarbour
    ? cString

    or with a function:

    cString:=a2s(aStrings)
    ? CSTRING

    func a2s(aArr)
    local cRes:="",t
    for t:=1 to len(aArr)
    cRes=cRes+rtrim(aArr[t])+hb_eol() // hb_OsNewLine xHb","
    next t
    return cRes
    Thank you very much for your precious answer my dear brother i had implement your nice code but unfortunately it could not reconstruct the image file i have read it with MEMOREAD function and i put it in an array and i follow your code but the image
    could not be built again my code is as follow so please advice me what should i do :

    procedure pStart()
    StringPool := {}
    cString := ""
    GetFile := GetFile ( { {"Text","*.txt"}, {"Image","*.JPG" } } , ;
    " Select File " , ;
    , ;
    , ;
    )
    MyStr = MEMOREAD ( GetFile )
    nline = MLCOUNT( MyStr , 254 )
    FOR x = 1 TO nline STEP 1
    vline = MEMOLINE( MyStr , 254 , x )
    AADD( StringPool , vline)
    Next
    cString = ArrayToString ( StringPool )
    RPWI_TH = FCREATE("C:\Users\Roklasfon\Desktop\Roklasfon.jpg",0) FWRITE(RPWI_TH,cString)
    FCLOSE(RPWI_TH)
    return
    Function ArrayToString ( aVessel )
    Local cRes
    cRes := ""
    VesselLength = LEN(aVessel)
    FOR t = 1 TO VesselLength STEP 1
    cRes := cRes+RTRIM(aVessel[t])+hb_eol()
    Next
    Return cRes

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rodrego sandino@21:1/5 to dlzc on Wed Jun 30 13:31:02 2021
    On Tuesday, June 29, 2021 at 9:53:42 PM UTC, dlzc wrote:
    Dear sandin...:
    On Tuesday, June 29, 2021 at 12:26:37 PM UTC-7, sandin...@gmail.com wrote:
    On Tuesday, June 29, 2021 at 3:57:02 PM UTC, rodrego sandino wrote:
    Is there any way to convert an array to string where each
    element can be access directly like in MEMOREAD function
    when it reads file you can access each line in file easily by
    MEMOLINE function .
    What do you know about the data type of the elements in the array? What do you know about the dimensonality of the arrays, as in how many parameters there are (uArray(1,2,3,4,5) := codestring)? If more than one dimension (row AND column), do you need
    to know "position"?

    I'd use this as a template: https://github.com/harbour/core/blob/master/tests/foreach.prg

    David A. Smith
    The data type in array is string and array is single dimension array

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniele@21:1/5 to All on Sat Jul 3 09:39:10 2021
    Il 30/06/2021 22:29, rodrego sandino ha scritto:

    Thank you very much for your precious answer my dear brother i had implement your nice code but unfortunately it could not reconstruct the image file i have read it with MEMOREAD function and i put it in an array and i follow your code but the image
    could not be built again my code is as follow so please advice me what should i do :

    Your approach is completely wrong, sorry. You are trying to read a jpg
    image as a text with memoread(), this can't work.

    Back to basics: memoread() reads text files.

    A text file contains a limited range of bytes, used to store text,
    usually in lines separated by a EOL, so that lines of text can be
    counted and extracted.

    A jpeg file is called a "binary" file. It contains raw bytes intended to
    be interpreted differently than a text file. No EOL separes no lines. To
    read such a file you should use Fread().

    What are you trying to do exactly?

    Dan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rodrego sandino@21:1/5 to Daniele on Mon Jul 5 10:31:02 2021
    On Saturday, July 3, 2021 at 7:39:16 AM UTC, Daniele wrote:
    Il 30/06/2021 22:29, rodrego sandino ha scritto:

    Thank you very much for your precious answer my dear brother i had implement your nice code but unfortunately it could not reconstruct the image file i have read it with MEMOREAD function and i put it in an array and i follow your code but the image
    could not be built again my code is as follow so please advice me what should i do :
    Your approach is completely wrong, sorry. You are trying to read a jpg
    image as a text with memoread(), this can't work.

    Back to basics: memoread() reads text files.

    A text file contains a limited range of bytes, used to store text,
    usually in lines separated by a EOL, so that lines of text can be
    counted and extracted.

    A jpeg file is called a "binary" file. It contains raw bytes intended to
    be interpreted differently than a text file. No EOL separes no lines. To read such a file you should use Fread().

    What are you trying to do exactly?

    Dan
    Thank you very much for your nice answer my dear brother ,so how i can reconstruct the image after i read with FRead() function as you saied?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rodrego sandino@21:1/5 to rodrego sandino on Mon Jul 5 13:57:06 2021
    On Monday, July 5, 2021 at 5:31:04 PM UTC, rodrego sandino wrote:
    On Saturday, July 3, 2021 at 7:39:16 AM UTC, Daniele wrote:
    Il 30/06/2021 22:29, rodrego sandino ha scritto:

    Thank you very much for your precious answer my dear brother i had implement your nice code but unfortunately it could not reconstruct the image file i have read it with MEMOREAD function and i put it in an array and i follow your code but the
    image could not be built again my code is as follow so please advice me what should i do :
    Your approach is completely wrong, sorry. You are trying to read a jpg image as a text with memoread(), this can't work.

    Back to basics: memoread() reads text files.

    A text file contains a limited range of bytes, used to store text,
    usually in lines separated by a EOL, so that lines of text can be
    counted and extracted.

    A jpeg file is called a "binary" file. It contains raw bytes intended to be interpreted differently than a text file. No EOL separes no lines. To read such a file you should use Fread().

    What are you trying to do exactly?

    Dan
    Thank you very much for your nice answer my dear brother ,so how i can reconstruct the image after i read with FRead() function as you saied?

    I had reconstruct the image as you said by using FRead and Fwrite .
    but i want to ask you question as you said before that MEMOREAD and MEMOWRITE are used to read text files only but i have used them to read image files before and it works by reading the image with MEMOREAD to string and read string again to file and it
    works but when i put the string in an array and try to reconstruct the string again in order to rebuild the image again it fails that is why i ask in the beginning how to convert an array of string to a single string so if you could help me to do that i
    will be thankful for you my dear brother.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ella Stern@21:1/5 to All on Mon Jul 5 14:21:14 2021
    "... but when i put the string in an array and try to reconstruct the string again in order to rebuild the image again it fails that is why i ask in the beginning how to convert an array of string to a single string..."

    In xHarbour the Array IS NOT implemented as in C or C++ the "dense array", and strings cannot include the NULL character (most of the time the blob objects are including NULL characters).
    The right way to work with image, sound, video etc. files is to handle them as blob objects when reading from or writing into a local file.
    Sending or receiving them over https is a different subject matter.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniele@21:1/5 to All on Tue Jul 6 06:32:45 2021
    Il 05/07/2021 22:57, rodrego sandino ha scritto:

    I had reconstruct the image as you said by using FRead and Fwrite .
    but i want to ask you question as you said before that MEMOREAD and MEMOWRITE are used to read text files only but i have used them to read image files before and it works by reading the image with MEMOREAD to string and read string again to file and
    it works

    I was not aware of the fact that memoread() reads everything and can
    handle binary files. I never used it that way. Good to know that it is a
    very robust function!

    but when i put the string in an array and try to reconstruct the
    string again in order to rebuild the image again it fails that is why i
    ask in the beginning how to convert an array of string to a single
    string so if you could help me to do that i will be thankful for you my
    dear brother.


    See the answer from Ella
    Dan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Daniele@21:1/5 to All on Tue Jul 6 06:51:58 2021
    Il 05/07/2021 23:21, Ella Stern ha scritto:

    "... but when i put the string in an array and try to reconstruct the string again in order to rebuild the image again it fails that is why i ask in the beginning how to convert an array of string to a single string..."

    In xHarbour the Array IS NOT implemented as in C or C++ the "dense array", and strings cannot include the NULL character (most of the time the blob objects are including NULL characters).
    The right way to work with image, sound, video etc. files is to handle them as blob objects when reading from or writing into a local file.
    Sending or receiving them over https is a different subject matter.

    To answer the OP, it would be possible then to use hb_Base64Encode() to
    fill the array with "chunks" of the original file encoded as pure ASCII.
    To reconstruct the file every line of the array will be decoded with hb_Base64Decode().

    Dan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rodrego sandino@21:1/5 to Ella Stern on Tue Jul 6 11:54:28 2021
    On Monday, July 5, 2021 at 9:21:15 PM UTC, Ella Stern wrote:
    "... but when i put the string in an array and try to reconstruct the string again in order to rebuild the image again it fails that is why i ask in the beginning how to convert an array of string to a single string..."

    In xHarbour the Array IS NOT implemented as in C or C++ the "dense array", and strings cannot include the NULL character (most of the time the blob objects are including NULL characters).
    The right way to work with image, sound, video etc. files is to handle them as blob objects when reading from or writing into a local file.
    Sending or receiving them over https is a different subject matter.
    ok..... how can i make blob object in xharbour ?and how i deal with them? please can you explain that with example?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rodrego sandino@21:1/5 to Daniele on Tue Jul 6 11:46:13 2021
    On Tuesday, July 6, 2021 at 4:52:06 AM UTC, Daniele wrote:
    Il 05/07/2021 23:21, Ella Stern ha scritto:

    "... but when i put the string in an array and try to reconstruct the string again in order to rebuild the image again it fails that is why i ask in the beginning how to convert an array of string to a single string..."

    In xHarbour the Array IS NOT implemented as in C or C++ the "dense array", and strings cannot include the NULL character (most of the time the blob objects are including NULL characters).
    The right way to work with image, sound, video etc. files is to handle them as blob objects when reading from or writing into a local file.
    Sending or receiving them over https is a different subject matter.

    To answer the OP, it would be possible then to use hb_Base64Encode() to
    fill the array with "chunks" of the original file encoded as pure ASCII.
    To reconstruct the file every line of the array will be decoded with hb_Base64Decode().

    Dan
    can you explain that with simple example? so the i can understand it easly

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rodrego sandino@21:1/5 to Daniele on Sun Jul 11 03:07:51 2021
    On Tuesday, July 6, 2021 at 4:52:06 AM UTC, Daniele wrote:
    Il 05/07/2021 23:21, Ella Stern ha scritto:

    "... but when i put the string in an array and try to reconstruct the string again in order to rebuild the image again it fails that is why i ask in the beginning how to convert an array of string to a single string..."

    In xHarbour the Array IS NOT implemented as in C or C++ the "dense array", and strings cannot include the NULL character (most of the time the blob objects are including NULL characters).
    The right way to work with image, sound, video etc. files is to handle them as blob objects when reading from or writing into a local file.
    Sending or receiving them over https is a different subject matter.

    To answer the OP, it would be possible then to use hb_Base64Encode() to
    fill the array with "chunks" of the original file encoded as pure ASCII.
    To reconstruct the file every line of the array will be decoded with hb_Base64Decode().

    Dan
    Thank you very much my dear brother it works ....you help me a lot...thank you very much.
    i have other question for you please ...how i can convert text file to PDF file in xHarbour ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to All on Tue Jul 13 13:48:41 2021
    how i can convert text file to PDF file in xHarbour ?

    https://groups.google.com/g/comp.lang.xharbour/c/WiguItHVeOg/m/kM532U6Y3eMJ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)