Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

finding the first character in a string that is in another set of characters

Posted on 2007-07-31
6
Medium Priority
?
235 Views
Last Modified: 2013-11-26
asp.net string csharp question..  I have a string that has a number 1001ADDKKEK, how can I find the first non numeric charater in the string?

example 1001ADDKKEK or 10010DKKKKEK - find the first non numeric character and return it's position.
0
Comment
Question by:cenetadmin
6 Comments
 
LVL 8

Expert Comment

by:sabeesh
ID: 19605866
string s = "00000Sdfaz";
        Regex r = new Regex("[A-Z]");
        Match m = r.Match(s);
        if (m.Success)
        {
            s = s.Substring(m.Index);
        }

hope this will work
0
 
LVL 8

Accepted Solution

by:
sabeesh earned 1500 total points
ID: 19605870
if u want u can ingonore case

 string s = "00000sdfaz";
        Regex r = new Regex("[A-Z]",RegexOptions.IgnoreCase);
        Match m = r.Match(s);
        if (m.Success)
        {
            s = s.Substring(m.Index);
        }
        Response.Write(s);
0
 
LVL 21

Expert Comment

by:Yurich
ID: 19605957
Just slightly modified

Regex reg = new Regex( @"\D" );
Match match = reg.Match( input );

if( match.Success )
{
      label1.Text = input.Substring( match.Index, 1 );
}

used non-numeric, and added the length of the substring (he needs the first character).
Cheers,
Yurich
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:Yurich
ID: 19605958
label1.Text is your output, I just used a lable ;)
0
 

Author Comment

by:cenetadmin
ID: 19607746
thanks for the assistance.  I will try these and let you know.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 19608672
Hi cenetadmin;

For the above solutions you will need to add the name space:

    using System.Text.RegularExpressions;

Fernando
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Loops Section Overview
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question