Hi all,
I have a string which consist of some numbers.I want to collect the numbers only.
For example
Jitu123456
Output will be
123456
How to do it?
Thanks
Regards
Jitu
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 30, 2011, 1:14 AM EST
Try this...
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Imports System.Text.RegularExpressions
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btncollect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncollect.Click
lblMessage.Text = CollectNumbers(txtInput.Text)
End Sub
Public Function CollectNumbers(ByVal collectnum As String) As String
Return String.Join(Nothing, Regex.Split(collectnum, "[^\d]"))
End Function
End Class
Thanks
VulpesRank #55 · 29.2K reputationPosted Dec 30, 2011, 4:14 AM EST
Jitendra Sahoo4 reputationPosted Dec 30, 2011, 5:03 AM EST
Sushta Guthnar110 reputationPosted Jan 1, 2012, 8:46 AM EST
You can also do it using LINQ:
Imports System
Imports System.Linq
Module Test
Sub Main
Dim s As String = "Jitu123456"
Dim n As String = New String(s.Where(Function(c) Char.IsDigit(c)).ToArray)
Console.WriteLine(n) '123456
End Sub
End Module
Vulpes takings giving me many happy feelings. Linq is the better of the leaves. Haveing one Linq statement is better than 3 in the bushes.
I agree and would like Vulpes to be haveing his answerings be marked as the fullest!-90
Happinesses in expert codeings.
Shusta