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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 30, 2011, 6:14 AM
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
Sushta GuthnarPosted Jan 1, 2012, 1:46 PM
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
Jitendra SahooPosted Dec 30, 2011, 10:03 AM
VulpesPosted Dec 30, 2011, 9:14 AM