Author Topic: how to get variable without numbers at end  (Read 594 times)

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
how to get variable without numbers at end
« on: October 13, 2016, 10:23:42 am »
pparts = vvijay_labx_wtl*
 // Here how to get site var as wtl not wtl1 or wtl2
_str pparts[];
         split(src, FILESEP, pparts); 
           if (pparts._length() > 2)
           {
              // split root/viewname, get usr (1st), viewtype (2nd last) and site (last)
              _str uparts[];
              split(pparts[1], '_', uparts);  
              if (uparts._length() > 2)
              {
                usr = uparts[0];
                site = uparts[uparts._length() -1];
                viewtype = uparts[uparts._length() -2];

Graeme

  • Senior Community Member
  • Posts: 1921
  • Hero Points: 220
Re: how to get variable without numbers at end
« Reply #1 on: October 13, 2016, 11:45:54 am »
If you just want to drop the last character in site then

site = uparts[uparts._length() -1];
if (site._length() > 1)
    site = substr(site, 1, site._length() - 1);

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: how to get variable without numbers at end
« Reply #2 on: October 13, 2016, 12:04:32 pm »
If last char is numeric and string length greater than 3 then i want to strip it.

Graeme

  • Senior Community Member
  • Posts: 1921
  • Hero Points: 220
Re: how to get variable without numbers at end
« Reply #3 on: October 13, 2016, 12:10:54 pm »
if (site._length() > 3 && is_digit(last_char(site)))
    site = substr(site, 1, site._length() - 1);

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: how to get variable without numbers at end
« Reply #4 on: October 13, 2016, 03:00:26 pm »
i get message
Procedure is-digit not found

Graeme

  • Senior Community Member
  • Posts: 1921
  • Hero Points: 220
Re: how to get variable without numbers at end
« Reply #5 on: October 13, 2016, 08:24:54 pm »
Sorry, isdigit  - see string functions in the help.

boolean isdigit(_str key)
{
  if ( length(key)>1 ) { return (false); }
  return(key>='0' && key<='9');

}