- SAP ABAP Advanced Cookbook
- Rehan Zaidi
- 250字
- 2021-08-05 18:21:57
Removal of characters from a string
In this recipe, we will see how special characters and blanks may be removed from a text string comprising of a telephone number. We will create a program that will take as input the number containing blank spaces and special characters such as +
, (
, and )
.
The replace
statement along with suitable regular expressions will be used. Various regular expressions may work in this case. We will see two such expressions in this recipe.
How to do it...
For meeting the mentioned requirement, proceed as follows:
- Declare a parameter by the name
number
, consisting of20
characters. - The
replace all occurrences
is added having the regular expression[^\d]
.
How it works...
The solution is based on searching all non-digit characters in the string and replacing them with blank. The negated operator (^
) is used within the box brackets and the \d
denotes the digits. We have used all occurrences, as this will replace all non-digits.
Suppose the user enters the number having +
and parentheses and blank spaces.

This will remove all special characters, as well as spaces, and will only display numbers.

There's more...
Alternately, you may also use [0-9]
in place of \d
. The regex will be then be written as '[^0-9]'
. In addition, it is important to include regex
in the replace
statement. Otherwise, instead of searching the pattern within the text, the system searches for [^\d]
or [^0-9]
in the text, and the desired results will not be achieved.
- 審計學
- 審計學基礎
- VMware vCloud Director Essentials
- 審計綜合模擬實訓
- Big Data Visualization
- 企業能源審計與節能規劃
- Microsoft Dynamics CRM 2011 Scripting Cookbook
- 陜西文物年鑒·2015
- 《企業內部控制基本規范》合規實務指南
- Microsoft Dynamics NAV
- Tableau:Creating Interactive Data Visualizations
- 2017年度注冊會計師全國統一考試專用教材(圖解版):審計
- 政策建模技術:CGE模型的理論與實現
- Oracle Primavera Contract Management,Business Intelligence Publisher Edition v14
- Learn Power Query