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 6373717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:23:49+00:00 2026-05-25T01:23:49+00:00

string dosage = "2/3/5 mg"; string[] dosageStringArray = dosage.Split(‘/’); int[] dosageIntArray = null; for

  • 0
string dosage = "2/3/5 mg";
string[] dosageStringArray = dosage.Split('/');
int[] dosageIntArray = null;
for (int i = 0; i <= dosageStringArray.Length; i++) 
{
    if (i == dosageStringArray.Length)
    {
        string[] lastDigit = dosageStringArray[i].Split(' ');
        dosageIntArray[i] = Common.Utility.ConvertToInt(lastDigit[0]);
    }
    else
    {
        dosageIntArray[i] = Common.Utility.ConvertToInt(dosageStringArray[i]);
    }
}

I am getting the exception on this line: dosageIntArray[i] = Common.Utility.ConvertToInt(dosageStringArray[i]);
I am unable to resolve this issue. Not getting where the problem is. But this line int[] dosageIntArray = null; is looking suspicious.

Exception: Object reference not set to an instance of an object.

  • 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-25T01:23:50+00:00Added an answer on May 25, 2026 at 1:23 am

    The biggest problem with your solution is not the missing array declaration, but rather how
    you’d parse the following code:

    string dosage = "2/13/5 mg";
    

    Since your problem is surely domain specific, this may not arise, but some variation of two digits representing same integer.

    The following solution splits the string on forward slash, then removes any non-digits from the substrings before converting them to integers.

    Regex digitsOnly = new Regex(@"[^\d]");   
    var array = dosage.Split('/')
                      .Select(num => int.Parse(digitsOnly.Replace(num, string.Empty)))
                      .ToArray();
    

    Or whatever that looks like with the cuddly Linq synthax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

string strLine;//not constant int index = 0; while(index < strLine.length()){//strLine is not modified}; how
How can i solve below string join error. i converted int value to string
string sentence = "X10 cats, Y20 dogs, 40 fish and 1 programmer."; string[] digits
string s1 = 1234; string s2 = 1234.65; string s3 = null; string s4
string[,] desc = new string[255,10]; int descLines = 0; cont string RDATAPATCH = rctdata.xdb;
string aux; int maxy, auxx = 0; cin >> aux; maxy = (int)sqrt(aux.size()); Why
String value = (String) request.getParameter(value); sometimes return null. How can I fix this? I
[String.Format(&quot;/build Debug {0}\Sources\Source\Infrastructure\Infrastructure.Interface\Infrastructure.Interface.csproj&quot;, BuildDirectory)] Say I want to have another double quotes from ===>
String.split(String regex) splits the string around a given regular expression and returns an String
String s = ; for(i=0;i<....){ s = some Assignment; } or for(i=0;i<..){ String s

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.