Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: Text formating  (Read 3321 times)

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Text formating
« on: December 15, 2017, 12:00:12 PM »
Hello,
I would like to use a "counter" within a text field like
1st
2nd
3rd
4th
...
21st
22nd
23rd
24th
...
and so on.
Is there a possibility to do this in a way, that makes sure that the 2718th entry is also formatted correct?

Paul

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: Text formating
« Reply #1 on: December 15, 2017, 12:06:24 PM »
PS.: How can I format a text within LimeReport to get something like this "HelloHello "???

Paul
« Last Edit: December 15, 2017, 12:08:58 PM by Paul Traut »

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 992
    • View Profile
Re: Text formating
« Reply #2 on: December 15, 2017, 01:12:23 PM »
Hi
You can write something like this in the init script
Code: [Select]
function formatNumber(number){
  var lastNumber = number.toString().charAt(number.toString().length-1);
  switch(lastNumber){
      case "1":
         result = "<sup>st</sup>"
      break;
      case "2":
          result = "<sup>nd</sup>"
      break;
      ......
  }
  return number.toString()+result;
}
And use it in a TextItem with AlloHTML
Code: [Select]
$S{formatNumber(12)}

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: Text formating
« Reply #3 on: December 15, 2017, 02:35:59 PM »
Ok, thanks.

But this means, I have to write within the script a case for every single number that I could expect ???

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: Text formating
« Reply #4 on: December 15, 2017, 03:50:11 PM »
Hello Alex,
this code doesent work right, I get
1<sup>st</sup>
2<sup>nd</sup>
...

as a result and not
1st
2nd
...

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 992
    • View Profile
Re: Text formating
« Reply #5 on: December 15, 2017, 03:56:55 PM »
Case should process only the last digit in the number.
Do you turn on AllowHTML at TextItem?

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: Text formating
« Reply #6 on: December 15, 2017, 04:04:40 PM »
Oh
I have over read this important information, now it works  ;D Thanks.

Can I also use the MOD operator within the script, than it would be easier to write a script for an unknown amount of lines
 :)

Fynjy

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Text formating
« Reply #7 on: December 18, 2017, 10:12:56 AM »
Hi
You can write something like this in the init script
Code: [Select]
function formatNumber(number){
  var lastNumber = number.toString().charAt(number.toString().length-1);
  switch(lastNumber){
      case "1":
         result = "<sup>st</sup>"
      break;
      case "2":
          result = "<sup>nd</sup>"
      break;
      ......
  }
  return number.toString()+result;
}
А куда этот код запихивать? Туплю немного)

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: Text formating
« Reply #8 on: December 18, 2017, 11:23:36 AM »
Hello Fynjy,
unfortunately, I can not read Russian  :(

Subst

  • Sr. Member
  • ****
  • Posts: 444
    • View Profile
Re: Text formating
« Reply #9 on: December 18, 2017, 11:31:44 AM »
Paul, the question by Fynjy about the init script location in LMDesigner...

Fynjy: смотри файл, там стрелкой указано, где инит скрипт располагать

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 992
    • View Profile
Re: Text formating
« Reply #10 on: December 18, 2017, 12:11:03 PM »
Paul,
Quote
Can I also use the MOD operator within the script, than it would be easier to write a script for an unknown amount of lines
Limereport uses javascript. In javascrip Modulus (%) operator returns only the remainder. 

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: Text formating
« Reply #11 on: December 18, 2017, 02:39:11 PM »
Paul, the question by Fynjy about the init script location in LMDesigner...

Fynjy: смотри файл, там стрелкой указано, где инит скрипт располагать
Ok, Thanks

Paul,
Quote
Can I also use the MOD operator within the script, than it would be easier to write a script for an unknown amount of lines
Limereport uses javascript. In javascrip Modulus (%) operator returns only the remainder. 

Thanks, will use this

Paul Traut

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: Text formating
« Reply #12 on: December 18, 2017, 04:43:00 PM »
Ok,

here is my solution. Maybe someone is searching for the same in the future
 :)
Code: [Select]
function formatNumber(number)
{
    var modNumber = number % 10;
    switch(modNumber)
    {
        case 1 :
        {
             tensDigit = number.toString().charAt(number.toString().length-2);
             switch(tensDigit)
            {
                 case "1":
                     result = "<sup>th</sup>"
                 break;
                 default:
                     result = "<sup>st</sup>"
                 break;
            }
        }
      break;
      case 2 :
          result = "<sup>nd</sup>" 
      break;
      case 3 :
          result = "<sup>rd</sup>"
      break;
      default:
          result = "<sup>th</sup>"
      break;
    }
    return number.toString()+result;
}