cancel
Showing results for 
Search instead for 
Did you mean: 

how to Numeric values from String

Haribp
Level 3
I Have a string that contains alphabets and numbers and Special characters .How can i get only numbers from string using blueprism?

------------------------------
Hari bp
------------------------------
1 BEST ANSWER

Helpful Answers

NaveenRPA
Level 4
Hi Hari,

You can extract numbers from a string by using Right, Left, IsNumber Functions natively, without using code stage or Regex.
22813.jpg

And

22814.jpg




------------------------------
naveen k
------------------------------

View answer in original post

4 REPLIES 4

PabloSarabia
Level 11
Hi @Haribp

​In this case you can use the typical conversion functions. (ToNumber())

You will need to use some code to achieve this.

With this code, you will get from the string "ab2c3d1" this 231 as a Number

string content = string.Empty;
for (int i=0; i< text.Length; i++)
{
if (Char.IsDigit(text))
{
content += text;
}
}

if (b.Length>0)
{
integer = int.Parse(b);
}
else
{
integer = 0;
}


In this case, "text" is your input value. Your string with alphanumerics and numbers.

And "integer" is your output value. I cast this as a number at the end.



Hope this helps you. And if this solves the problem, remember mark as the best answer 🙂

See you in the community, bye 🙂

------------------------------
Pablo Sarabia
Architect
Altamira Assets Management
Madrid
------------------------------

As an alternative to the code stage, Regex could be considered. With a pattern in style with "\d+" or perhaps "[0-9]+" to extract only numerical values from a given text string.

------------------------------
Happy coding!
Paul
Sweden
------------------------------
Happy coding!
Paul, Sweden
(By all means, do not mark this as the best answer!)

NaveenRPA
Level 4
Hi Hari,

You can extract numbers from a string by using Right, Left, IsNumber Functions natively, without using code stage or Regex.
22813.jpg

And

22814.jpg




------------------------------
naveen k
------------------------------

MichealCharron
Level 8
@Haribp

Adding to @PvD_SE's reply, rather than using the "Regex Extract" action in BP's Utility String VBO​​, you can use the "Regex Replace" action to replace all non numeric characters with blanks. It is one action that passes out the value to one text data item.

If you can't make it out from the image, the parameters are:
Pattern: "[^0-9]"
Input Data: "The123Rain456In789Spain!@#$."
Replacement Data: ""

22815.png

The Regex pattern "[^0-9]" uses a negative character group [^] to specify any character not between 0 and 9 (inclusive) in a Unicode codespace.

------------------------------
Micheal Charron
Senior Manager
RBC
America/Toronto
------------------------------
Micheal Charron
RBC
Toronto, Ontario
Canada