Detect underscore in formname and trim.

Questions, tips and tricks and techniques for scripting in Servoy

Detect underscore in formname and trim.

Postby 4xjbh » Sun Jun 13, 2010 11:26 am

My form names are all named like 'home_lst_defect' or "defect_frm_main".

How do I cycle through each character to find underscore so I can then trim and use in a method.

Thanks
Regards,

James
4xjbh
 
Posts: 146
Joined: Fri Feb 24, 2006 8:06 am
Location: Brisbane, Australia

Re: Detect underscore in formname and trim.

Postby 4xjbh » Sun Jun 13, 2010 12:06 pm

OK, I have this to get last part of string, having trouble with getting first part.
Code: Select all
var x ="home_defect_test"
var div = x.lastIndexOf("_")+1
var y = x.substring(div,x.length)
Regards,

James
4xjbh
 
Posts: 146
Joined: Fri Feb 24, 2006 8:06 am
Location: Brisbane, Australia

Re: Detect underscore in formname and trim.

Postby Harjo » Sun Jun 13, 2010 12:18 pm

why do you need to trim the '_' for using in a method?

you can do this:

Code: Select all
var myform = 'home_lst_defect'
forms[myform].controller.loadAllRecords() // just an example, do what ever you want to do here....
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Detect underscore in formname and trim.

Postby ROCLASI » Sun Jun 13, 2010 12:25 pm

Hi James,

What Harjo said.

Also when you want to parse a string like that you could use arrays.
Code: Select all
var _sForm = "home_lst_defect",
    _aForm = _sForm.split("_");
// _aForm[0] gives first part
// _aForm[1] gives second part
// _aForm[2] gives third and last part
_sForm = _aForm.join(""); // make a string again without underscores
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Detect underscore in formname and trim.

Postby 4xjbh » Sun Jun 13, 2010 1:42 pm

I worked out how to do it with a loop but I like the use of arrays.

I did not need to trim the underscores just detect the first word before the first underscore and the last word after the last underscore.

Split will do it. Thanks heaps
Regards,

James
4xjbh
 
Posts: 146
Joined: Fri Feb 24, 2006 8:06 am
Location: Brisbane, Australia


Return to Methods

Who is online

Users browsing this forum: No registered users and 27 guests