Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Strings involving the character '-'



  • Please log in to reply
2 replies to this topic
Jeffrey562
  • Members
  • 22 posts
  • Last active: Apr 30 2015 08:08 PM
  • Joined: 03 Apr 2015

Hi folks,

 

I will describe two procedures that I am having difficulty executing. Solutions to either one would be greatly appreciated.

 

1. Given two strings A and B (say, for example 513 and 3, respectively), how can the string %A%-%B% (513-3) be saved to a variable?

 

2. Given a string A containing exactly one '-' (say, for example 513-3), how can I produce the substrings which precede '-' (513) and follow '-' (3)?

The difficulty here is that I cannot search for the position of the character '-'.

 

Thanks,

Jeff



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012
✓  Best Answer

1) variable:=A "-" B or variable=%A%-%B%

 

Take a look at operators to understand the difference between := (which treats everything to the right as an expression) and = (which treats things to the right as literal).

 

2) To clarify, you want to split a string into it's first and second components? There are many ways, but perhaps this would work using StringSplit:

 

StringSplit, OutputArray, A, -
MsgBox %OutputArray1%
MsgBox %OutputArray2%
return


Jeffrey562
  • Members
  • 22 posts
  • Last active: Apr 30 2015 08:08 PM
  • Joined: 03 Apr 2015

Exaskryz,

 

Thanks for your prompt reply. Both of your suggestions work well. Thanks also for pointing me to look at operators.