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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to extract variable sized numbers in character array 1

Status
Not open for further replies.

willy113

Programmer
Apr 27, 2004
33
US
I am looking for help or code examples on how to extract a series of numbers in a string that are always seperated by a "white space".

The following code example worked fine when I knew that the numbers were always going to be 2 bytes long, using the ProcommPlus "substr" command.
Now the program needs to be modified to support numbers in a character string with variable lentgh sizes of 1, 2 or 3 bytes.

integer TempStrIndex = 0 ; for Temp Status module
string TempStatOutputStr[3] ; for Temp Status module
string TempStatStrArr[3][4] ; for Temp Status module
integer TempStatIntArr[3][4] ; for Temp Status module
integer TempHiLimit = 0 ; for Temp Status module
integer TempLoLimit = 0 ; for Temp Status module

ArrIndex = 0, ArrIndex2 = 3
TempStatStrArr[ArrIndex][ArrIndex2] = TempStatOutputStrArrIndex]

substr TempStatStrArr[1][0] TempStatOutputStr[1] 1 2
substr TempStatStrArr[1][1] TempStatOutputStr[1] 6 2
substr TempStatStrArr[1][2] TempStatOutputStr[1] 11 2
substr TempStatStrArr[1][3] TempStatOutputStr[1] 15 10

Can I use the "sizeof" parameter somehow to replace where
the "fixed number size = 2" value is in the substr command shown above ??

Best Regards, willy113
 
Probably the easiest thing to do would be to use the strextract command to pull out the string "chunk" that you are needing. If you can post some example data that is contained in the array, I can probably let you know if strextract or another command should work for you.




aspect@aspectscripting.com
 
Hi Knob,

Thanks for your quick response on the ProcommPlus question !!

I am using RGET to get the data stream from a Fibre CHannel switch via RS-232 and Telnet ports.

The data starts with a "white space" then seperates or delimits the rest of the data with 3 "white spaces".

Here is a snippet out of my test log (Procomm Capture)
Switch Temperature Show Status RGET Module#1a Data is: tempShow


Switch Temperature Show Status RGET Module#1b Data is:

37 33 31 Centigrade


Switch Temperature Show Status RGET Module#2 Data is: 98 91 87 Fahrenheit


Switch Temperature Show Status RGET Total Data is: tempShow

37 33 31 Centigrade

98 91 87 Fahrenheit


Switch Temperature CENTIGRADE Data was found OK:
37 33 31 Centigrade


Switch Temperature FAHRENHEIT Data was found OK:
98 91 87 Fahrenheit


Switch Temperature Status for Temp Probe #1 PASSED at 37 C: Exp Range: 20 - 48 C

Switch Temperature Status for Temp Probe #2 PASSED at 33 C: Exp Range: 20 - 48 C

Switch Temperature Status for Temp Probe #3 PASSED at 31 C: Exp Range: 20 - 48 C

Switch Temperature Status for Temp Probe #1 PASSED at 98 F: Exp Range: 68 to 118 F

Switch Temperature Status for Temp Probe #2 PASSED at 91 F: Exp Range: 68 to 118 F

Switch Temperature Status for Temp Probe #3 PASSED at 87 F: Exp Range: 68 to 118 F

I load each Procomm terminal line into it's own array element and raw data can be 1, 2 or 3 bytes in width, like a temperature of 9, 50, 120, ETC.

- Bill Lusche
 
Here are a couple examples to get you going. First for this string:

37 33 31 Centigrade

You can use these commands to get the first two values:

strextract TempStatStrArr TempStatOutputStr " " 0
strextract TempStatStrArr TempStatOutputStr " " 1

To get the third value, you would need to use two separate commands since there are two spaces after 31 and not three spaces like the previous data points:

strextract Temp TempStatOutputStr " " 2
strextract TempStatStrArr Temp " " 0

Note that I had to use a temporary variable in the process.

To get the temperatures from this line:

Switch Temperature Status for Temp Probe #1 PASSED at 37 C: Exp Range: 20 - 48 C

you would use these two commands:

strextract TempStatStrArr TempStatOutputStr " " 13
strextract TempStatStrArr TempStatOutputStr " " 15

aspect@aspectscripting.com
 
Hi Knob,

One quick question on your last response on the strextract code samples ....

1. So what will the final formatted data look like in the "Target" string for the output (TempStatStrArr) ??
- Will there be any spaces or delimiters between each of the written output characters as the result of the multiple uses of the strextract command in your example ??
- Will data now be: 3733312048 ?????

2. Another thought would be to load each strextract output to an indivdual element in a 2-deminsional array .....

- Bill
 
Each individual strextract command above (except for the case where two different commands are needed to get the value for lines of the form "37 33 31 Centigrade") would have one value in the output string. I didn't use the arrays as you had in your examples, but you could assign each value to an array element as you were doing before (I was just trying to make my work a little easier).

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top