Truncate text on number of characters or space

Dear all,

I want to truncate (?) text that has been inputted in two ways: Truncate to
the first letter and truncate on space. So for example, a full name was
entered:

Emilio Sanches Cordoba

a) I would then like to truncate on the first letter >> 'E' and use this as
a variable/label for the remaining questions

b) I would also like to truncate on the first name >> 'Emilio' and use this
as a variable/label for the remaining questions

Can someone explain me how I could do this in code? For a) I have tried
working with regex(${basic_name_producer2}, '^[A-Z]') and
substr(${basic_name_nickname},1,2) but it does not seem to work. For b) I
have no idea how to do this. Thanks in advance!

Regards,

Hi Eddy,

Item B might be tough, I would probably prefer to either split the name
input question into given and family name items, or ask them to just enter
the name they prefer to be called or something. Basically make them enter
it already split so you don't have to do it.

For Item A, a regex in ODK is a true/false check. It doesn't actually
output a substring, it just tests whether the entered response fits the
mask defined by the regex. So that isn't going to help you any in this
case.

Substring should work. I notice from what you entered below, you are
starting with 1 and ending with 2. The character count function starts
with 0, so doing that on the example you gave below should return 'm'. If
you want 'E', it would need to be substr(${basic_name_nickname}, 0, 1).

If that still isn't working you may have issues with your reference or
something that would require more info to diagnose.

Jason

ยทยทยท On Wednesday, November 30, 2016 at 4:28:21 AM UTC-5, Eddy Rellum wrote: > > Dear all, > > I want to truncate (?) text that has been inputted in two ways: Truncate > to the first letter and truncate on space. So for example, a full name was > entered: > > Emilio Sanches Cordoba > > a) I would then like to truncate on the first letter >> 'E' and use this > as a variable/label for the remaining questions > > b) I would also like to truncate on the first name >> 'Emilio' and use > this as a variable/label for the remaining questions > > Can someone explain me how I could do this in code? For a) I have tried > working with regex(${basic_name_producer2}, '^[A-Z]') and > substr(${basic_name_nickname},1,2) but it does not seem to work. For b) I > have no idea how to do this. Thanks in advance! > > Regards, >
1 Like

Thanks Jason. This was the solution.

ยทยทยท On Thursday, December 1, 2016 at 3:39:52 PM UTC+1, Jason Ives wrote: > > Hi Eddy, > > Item B might be tough, I would probably prefer to either split the name > input question into given and family name items, or ask them to just enter > the name they prefer to be called or something. Basically make them enter > it already split so you don't have to do it. > > For Item A, a regex in ODK is a true/false check. It doesn't actually > output a substring, it just tests whether the entered response fits the > mask defined by the regex. So that isn't going to help you any in this > case. > > Substring should work. I notice from what you entered below, you are > starting with 1 and ending with 2. The character count function starts > with 0, so doing that on the example you gave below should return 'm'. If > you want 'E', it would need to be substr(${basic_name_nickname}, 0, 1). > > If that still isn't working you may have issues with your reference or > something that would require more info to diagnose. > > Jason > > On Wednesday, November 30, 2016 at 4:28:21 AM UTC-5, Eddy Rellum wrote: >> >> Dear all, >> >> I want to truncate (?) text that has been inputted in two ways: Truncate >> to the first letter and truncate on space. So for example, a full name was >> entered: >> >> Emilio Sanches Cordoba >> >> a) I would then like to truncate on the first letter >> 'E' and use this >> as a variable/label for the remaining questions >> >> b) I would also like to truncate on the first name >> 'Emilio' and use >> this as a variable/label for the remaining questions >> >> Can someone explain me how I could do this in code? For a) I have tried >> working with regex(${basic_name_producer2}, '^[A-Z]') and >> substr(${basic_name_nickname},1,2) but it does not seem to work. For b) I >> have no idea how to do this. Thanks in advance! >> >> Regards, >> >

This is some great insight into helping me refine some of the forms that I
have already developed..

Thanks guys!

ยทยทยท sent from my Samsung Tablet

On Dec 7, 2016 6:11 PM, "Eddy Rellum" 4estsense@gmail.com wrote:

Thanks Jason. This was the solution.

On Thursday, December 1, 2016 at 3:39:52 PM UTC+1, Jason Ives wrote:

Hi Eddy,

Item B might be tough, I would probably prefer to either split the name
input question into given and family name items, or ask them to just enter
the name they prefer to be called or something. Basically make them enter
it already split so you don't have to do it.

For Item A, a regex in ODK is a true/false check. It doesn't actually
output a substring, it just tests whether the entered response fits the
mask defined by the regex. So that isn't going to help you any in this
case.

Substring should work. I notice from what you entered below, you are
starting with 1 and ending with 2. The character count function starts
with 0, so doing that on the example you gave below should return 'm'. If
you want 'E', it would need to be substr(${basic_name_nickname}, 0, 1).

If that still isn't working you may have issues with your reference or
something that would require more info to diagnose.

Jason

On Wednesday, November 30, 2016 at 4:28:21 AM UTC-5, Eddy Rellum wrote:

Dear all,

I want to truncate (?) text that has been inputted in two ways: Truncate
to the first letter and truncate on space. So for example, a full name was
entered:

Emilio Sanches Cordoba

a) I would then like to truncate on the first letter >> 'E' and use this
as a variable/label for the remaining questions

b) I would also like to truncate on the first name >> 'Emilio' and use
this as a variable/label for the remaining questions

Can someone explain me how I could do this in code? For a) I have tried
working with regex(${basic_name_producer2}, '^[A-Z]') and
substr(${basic_name_nickname},1,2) but it does not seem to work. For b)
I have no idea how to do this. Thanks in advance!

Regards,

--
--
Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


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