Author Topic: Trim spaces problem  (Read 6953 times)

TheThingIs

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 278
    • HCS Voicepacks
Trim spaces problem
« on: July 20, 2016, 09:07:36 AM »
trim spaces doesn't seem to work when I issue a command that also does a replace:

Set Text [Role] to '{LASTSPOKENCMD}' (Trim) (Replace '{TXT:Crew Name}' with ''

thanks,

TheThingIs
The Singularity profile - One profile to rule them all and at HCS we bound them ;)

You see, TheThingIs, eventually you'll be allright.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: Trim spaces problem
« Reply #1 on: July 20, 2016, 09:47:13 AM »
Also note the lack of a closing parenthesis for "Replace".

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Trim spaces problem
« Reply #2 on: July 20, 2016, 10:32:35 AM »
Since this is a caption from the command list, would it be possible for you to export and upload the command here or send to support@voiceattack.com?

TheThingIs

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 278
    • HCS Voicepacks
Re: Trim spaces problem
« Reply #3 on: July 22, 2016, 01:12:23 PM »
Here you go...
The Singularity profile - One profile to rule them all and at HCS we bound them ;)

You see, TheThingIs, eventually you'll be allright.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Trim spaces problem
« Reply #4 on: July 22, 2016, 06:48:17 PM »
Thanks for the heads-up.  I'll look into it once this storm is over... o_O

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Trim spaces problem
« Reply #5 on: July 23, 2016, 03:26:46 PM »
What output are you expecting and what are you getting?  I'm trimming and replacing and it seems ok.

Trim removes the spaces outside of a text value so, '     this is my text    '  would become, 'this is my text'.   'this   is     my      text' would require something else to normalize the text to single characters.

You would need to write a while loop that checks to see if the text contains two spaces and replace with a single space:

While myText contains '  '
    set myText = Replace '  ' with ' '
end while

I attached a sample profile that has a single command that does that.  I've added a note to add this functionality to VA.
« Last Edit: July 24, 2016, 10:06:02 PM by Gary »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: Trim spaces problem
« Reply #6 on: July 23, 2016, 05:08:58 PM »
I can't replicate the original bug, but Gary, in your example you have
Code: [Select]
Start Loop While : [Some Text] Contains ''
Set Text [Some Text] to [Some Text] (Trim) (Replace '  ' with ' '
End Loop
Which loops infinitely because you're checking if it contains 'blank'.
I'm assuming you were intending to check if it contained double spaces. Did this get trimmed automatically at some stage?

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Trim spaces problem
« Reply #7 on: July 23, 2016, 05:31:38 PM »
Weird... when I import the example, it has the proper spaces in there o_O
Should be replace double spaces with single.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4758
  • RTFM
Re: Trim spaces problem
« Reply #8 on: July 23, 2016, 06:38:29 PM »
Weird... when I import the example, it has the proper spaces in there o_O
Should be replace double spaces with single.

Redownloaded, reimported(into v1.5.10.2):
Code: [Select]
Start Loop While : [Some Text] Contains ''

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Trim spaces problem
« Reply #9 on: July 23, 2016, 09:12:44 PM »
Ah, yes... sorry.  Was looking in the wrong place.  Fixed and will be out in the next release.  Meanwhile, I will update the upload.

TheThingIs

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 278
    • HCS Voicepacks
Re: Trim spaces problem
« Reply #10 on: July 24, 2016, 04:47:07 AM »
did that fix the original problem?

Here's a simpler example.

The output I am after is *to comms* but I get * to comms*

The asterisks are there just to show where the spaces are and are not in the variable.

Lee
The Singularity profile - One profile to rule them all and at HCS we bound them ;)

You see, TheThingIs, eventually you'll be allright.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2827
Re: Trim spaces problem
« Reply #11 on: July 24, 2016, 10:01:01 PM »
Ack... my updated profile was wrong.  The loop was checking for a single space, which will always exist and the loop will just continue on until stopped.

Attached is a better example (text from command below).


Set Text [Some Text] to '      My crew       is     Team      Valor   '
Write '[Orange] {TXT:Some Text}' to log
Start Loop While : [Some Text] Contains '  '
    Set Text [Some Text] to [Some Text] (Trim) (Replace '  ' with ' ')
End Loop
Write '[Orange] {TXT:Some Text}' to log


Output should be
      My crew       is     Team      Valor   <---- before processing
My crew is Team Valor<---- after processing           
« Last Edit: July 24, 2016, 10:06:21 PM by Gary »