Actually, this is what is happening:

func Nitish(key *C.char, value *C.char, value_len C.size_t){

   f.WriteString(C.GoString(key)+ ":")
   f.WriteString(C.GoString(value))
   f.WriteString("\n")

}

This callback method is getting called from C code multiple times.

I am planning to write  the key, value pairs in a file.But the 'value'
field is getting appended with the previous value in the buffer.

These are the contents that are getting written to the file.Please see
the following from bottom to top.If you see for every key field
(bottom to top), image/gif and then 'Fp5PpR2roT6uPnte47' is getting
appended as I continue writing key-values to the file.

But I need only the first word from the value field.

Actual:

sentfileid: -       Fp5PpR2roT6uPnte47      image/gif
sentmimetype: Fp5PpR2roT6uPnte47      image/gif
rcvdfileid: image/gif

Expected:

sentfileid: -
sentmimetype: Fp5PpR2roT6uPnte47
rcvdfileid: image/gif

Please let me know how can I achieve this ?

Thanks



On Wed, May 1, 2019 at 11:25 AM Nitish Saboo <nitish.sabo...@gmail.com>
wrote:

> Hi,
> I have this method:
>
> func CallBack(key *C.char, value *C.char, value_len C.size_t){
>
>     }
>
> and the *value* parameter in the arguments is containing the given
> string  'Fp5PpR2roT6uPnte47      image/gif'.
> I want to extract only first word from the string.Let me know how can I do
> this.
>
> I don't want  to split the string into a slice of individual characters.
>
> Thanks
>
> On Wed, May 1, 2019 at 6:27 AM Justin Israel <justinisr...@gmail.com>
> wrote:
>
>>
>>
>> On Wednesday, May 1, 2019 at 7:06:47 AM UTC+12, Nitish Saboo wrote:
>>>
>>> Apologies.I did this 'strings.Split(C.GoString(*C.char),"").
>>> I am getting 'Incompatible types' compilation error.
>>>
>>
>> Are you literally doing this?
>>     strings.Split(C.GoString(*C.char),"")
>>
>> Something like this should be working correctly:
>>
>>     someCArr := getSomeCArr()
>>     chars := strings.Split(C.GoString(someCArr),"")
>>
>> Is your goal to split the string into a slice of individual characters?
>> Because that is what your delim suggests.
>>
>>
>>> Thanks
>>>
>>>
>>> On Wed, May 1, 2019 at 12:30 AM Nitish Saboo <nitish...@gmail.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> I want to convert *C.char to array of strings in Go.
>>>> I want to do this because I want the first word from the string.Strings
>>>> are getting appended to *C.char and I want the first word of the string.
>>>> I am doing it using 'strings.Split(C.GoString(*C.char))[0]', but it is
>>>> giving error.
>>>> Can someone correct me here ?
>>>>
>>>> Thanks
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "golang-nuts" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to golan...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to