# Thread: How to extract percentage and N/A from the string?

1. ## How to extract percentage and N/A from the string?

Friends,

I tried with different logics but could not get the result that I want.
Here is the string: "31.80%44.31%57.51%N/AN/AN/A24.50%"
I need to have value like below.
31.80%
44.31%
57.51%
N/A
N/A
N/A
24.50%

NOTE: The string can have N/A anywhere.
Such as:
"31.80%N/A57.51%N/AN/A44.31%24.50%"
"N/A44.31%57.51%N/A31.80%N/A24.50%"

and so on...

2. ## Re: How to extract percentage and N/A from the string?

does the order matter?

3. ## Re: How to extract percentage and N/A from the str

<font class="small">Code:</font><hr /><pre> Var = "31.80%44.31%57.51%N/AN/AN/A24.50%"
Dim MyArray()
i = 0
Do Until Len(Var) = 0
ReDim Preserve MyArray(i)
If i &gt; 0 Then
Var = Mid(Var,Len(MyArray(i-1))+1)
End If

If IsNumeric(Mid(Var, 1, 1)) Then
MyArray(i) = Mid(Var, 1, Instr(1, Var, "%"))
Else
MyArray(i) = Mid(Var, 1, 3)
End If
i = i + 1
Loop
For i = 0 To Ubound(MyArray)
Print MyArray(i)
Next
</pre><hr />

4. ## Re: How to extract percentage and N/A from the str

<font class="small">Code:</font><hr /><pre> s = trim( replace( replace( sInputString, "A", "A "), "%", "% "))
aResult = split( s, " ") </pre><hr />
Regards,
M

5. ## Re: How to extract percentage and N/A from the str

[ QUOTE ]
<font class="small">Code:</font><hr /><pre> s = trim( replace( replace( sInputString, "A", "A "), "%", "% "))
aResult = split( s, " ") </pre><hr />
Regards,
M

[/ QUOTE ]

Good idea.

6. ## Re: How to extract percentage and N/A from the str

I am sorry for not replying on time. but yes order does matter.

I almost got the answer. I am in middle of unit testing my code which I will post it soon.

7. ## Re: How to extract percentage and N/A from the str

Thanks TReddy. I tried your suggestion and it works fine.

Here what I have.

<font class="small">Code:</font><hr /><pre>
var="31.80%44.31%57.51%N/AN/AN/A24.50%"
Dim arrVal ,regEx
Set regEx = New RegExp
regEx.Pattern = "A|%"
regEx.Global = True
arrVal = Split( replace( regEx.Replace(var , ",") ,"N/","N/A") ,",")
</pre><hr />

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.