Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to do this

Status
Not open for further replies.

friend01

Programmer
Jun 4, 2009
94
CA
Hi,

I would need some help with the following. Here is an example string:

"- 05FOGB955568-004BLCA-000 - 10 - 5320 Jean Mance East - Halifax - HN - H1H 1H1 Comment: NMBA 1435 change from 100BT to 10BT"

I would like to have everything in between all the dashes to be variables. Example:

"- 05FOGB955568" = var1
"-004BLCA" = var2
"-000" = var3
"- 10" = var4
"- 5320 Jean Mance East" = var5
"- Halifax" = var6
"- HN" = var7
"- H1H 1H1" Comment: NMBA 1435 change from 100BT to 10BT = var8


The problem is that the "dashes" in each string can be anywhere and the number of dashes can vary. How can I get what the result. can anybody help?

thanks,
F1
 
Code:
lcstr = "- 05FOGB955568-004BLCA-000 - 10 - 5320 Jean Mance East - Halifax - HN - H1H 1H1 Comment: NMBA 1435 change from 100BT to 10BT"
var1 = substr(lcstr,at_c("-",lcstr,1)+1,at_c("-",lcstr,2)-2-at_c("-",lcstr,1)+1)
var2 = substr(lcstr,at_c("-",lcstr,2)+1,at_c("-",lcstr,3)-2-at_c("-",lcstr,2)+1)
var3 = substr(lcstr,at_c("-",lcstr,3)+1,at_c("-",lcstr,4)-2-at_c("-",lcstr,3)+1)
var4 = substr(lcstr,at_c("-",lcstr,4)+1,at_c("-",lcstr,5)-2-at_c("-",lcstr,4)+1)

Just keep changing the occurences.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Hi,

You may try this:

lnttlDash = OCCURS("-", lcString)
FOR lnDashnmr=1 TO lnttlDash
lnVar ='lnVar'+TRANSFORM(lnDashnmr)
lnVar = SUBSTR(lcString,1,AT("-",lcString)-1)
lcString = SUBSTR(lcString, LEN(lnVar)+2,LEN(lcString))
? lnVar
NEXT

lcString = your variable, and you may store the variable name (lnVar) in an array or object collection, all depending what you plan to do with the data.

Regards,

Jockey(2)
 
Code:
lcStr = "- 05FOGB955568-004BLCA-000 - 10 - 5320 Jean Mance East - Halifax - HN - H1H 1H1 Comment: NMBA 1435 change from 100BT to 10BT"
ALINES(aArray,lcStr,,"-")

?aArray[2] && 05FOGB955568

Ali Koumaiha
TeknoPCS Inc.
Dearborn heights, MI 48127
 
I'd also use ALINES(), much simpler and an array is what you need anyway, much simpler to handle than single variables.

As your strings start with a dash the first array element would always be empty, but that's a mild consequence of the nature of those strings, isn't it?

Bye, Olaf.
 
Hi,

Ali I agree a fine, quick example. Please change into

[blue]
ALINES(aArray,lcStr,4,'-')
[/blue]
Regards,

Jockey(2)
 
Jockey,

I don't know how i missed the 3rd parameter lol

it gives a syntax error without it, doesn't it?

Ali Koumaiha
TeknoPCS Inc.
Dearborn heights, MI 48127
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top