CodeSolved

A comprehensive source of programming questions and exercises

Extraction of in -text numbers

Practice Easy 1301/ Download 513 Views

Write a program that receives a text and extracts and prints the numbers inside.

For example:

Input: hooshang123hooshangi456
Output: 123456

17 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
import re
def extract_numbers(text):
    """
    این تابع اعداد موجود در متن را استخراج کرده و به صورت یک رشته برمی‌گرداند.
    """
    # Use Regex to find all numbers in the text
    numbers = re.findall(r'\d+', text)
    # Combining the extracted numbers to a string
    return ''.join(numbers)

# Get input from the user
input_text = input("لطفاً یک متن وارد کنید: ")
result = extract_numbers(input_text)

# Printing results
print("استخراج شده:", result)
Mma123 Download Python
Text = input("Enter your sentence:")
numbers = []
for char in Text:
    if char.isdigit():
        numbers.append(char)
print(numbers)
Matin Download Python
text = input('enter text: ')
for num in text:
    if num.isnumeric():
        print(num,end='')

I wrote this form too :) User 35


def numbers(t):
    num = []
    for i in text:
        if i.isdigit():
            num.append(i)
    return num

text = input('input: ')
print('output: ',numbers(text))
const str = "hooshang123hooshangi456";
const num = str.match(/\d{1,}/g);
console.log(num);
#include <iostream>
#include <string>
#include<cctype>
using namespace std;
int main(){
    int i;
    string a;
    cin>>a;
    for (i = 0 ; i < a.length() ; i++){
        if (isdigit(a[i])){
            cout<<a[i];
        }
    }
    return 0;
}
Aref.2 Download C & C++
y = input("tex : ")
x = ""
for i in y :
    if i.isdigit():
        x = x + i
print(x)
Aref.2 Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close