Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 790207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:38:47+00:00 2026-05-14T21:38:47+00:00

Could this be better? .NET 2.0 compatibility for SQL Server 2005: public static SqlString

  • 0

Could this be better? .NET 2.0 compatibility for SQL Server 2005:

public static SqlString RegexSubstring(SqlString regexpattern, 
                                       SqlString sourcetext, 
                                       SqlInt32 start_position)
{
   SqlString result = null;

   if (!regexpattern.IsNull && !sourcetext.IsNull && !start_position.IsNull)
   {
      int start_location = (int)start_position >= 0 ? (int)start_position : 0;

      Regex RegexInstance = new Regex(regexpattern.ToString());
      result = new SqlString(RegexInstance.Match(sourcetext.ToString(), 
                                                 start_location).Value);
   }

   return result;
}

This is my first attempt at writing CLR functions/etc for SQL Server – is it absolutely necessary to use SqlString/etc data types for parameters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:38:47+00:00Added an answer on May 14, 2026 at 9:38 pm

    Just running it through Refactor/Pro

    gave this:

    public static SqlString RegexSubstring(SqlString regexpattern,
                                   SqlString sourcetext,
                                   SqlInt32 start_position) {
        if (regexpattern.IsNull || sourcetext.IsNull || start_position.IsNull)
            return null;
    
        Regex RegexInstance = new Regex(regexpattern.ToString());
    
        return new SqlString(RegexInstance.Match(sourcetext.ToString(),
                                                   (int)start_position).Value);
    }
    

    Note that start_location is unused, so possibly you’re ignoring warnings?

    Another thing is just a matter of style, but can the function be written to not have a dependency on SqtTypes? Then the code becomes:

        private static string RegexSubstring(string regexpattern, string sourcetext, int start_position) {
    
            if (regexpattern == null || sourcetext == null || start_position == null)
                return null;
    
            Regex RegexInstance = new Regex(regexpattern);
            return RegexInstance.Match(sourcetext, start_position).Value;
        }
    

    and call it with :

    new SqlString(RegexSubstring(regexpattern.ToString(), sourcetext.ToString(), start_position))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I could probably think of a better title for this and open to suggestions)
Could this be done with javascript/jQuery : <div class=number>99,123,123</div> <div class=number>123,123,123</div> <div class=number>1,123,123,123</div> <div
I found this interesting behavior. Why could this happen I am using the cmdlet
I had accidentally tried this, which compiles! So I was wondering what could this
Hi: I want to redirect stdout to a NSTextView. Could this also work with
This could be a very basic Javascript I know but I just can't get
This could quite possibly be the dumbest question ever asked. Our client wants us
This could be considered a duplicate question, as a similar one has already been
This could save me so much time. Sometimes I find myself writing things like
This could be an amazingly dumb question, but .... I don't think a standard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.