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

  • Home
  • SEARCH
  • 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 8405685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:54:10+00:00 2026-06-09T22:54:10+00:00

All, Consider following piece of code: string message = abc;def;ghi; string[] msgs = message.Split(‘;’);

  • 0

All,

Consider following piece of code:

string message = "abc;def;ghi";
string[] msgs = message.Split(';');
string temp = msg[2] ? msg[2] : "Failed";

Message variable is coming from the server and has different length. I need to parse it so that if the value does not exist, result should be “Failed”.

Is there an easy way to do that?

Right now this construct gives comppiler error: “Cannot convert string to bool”.

Thank you.

[EDIT]

I guess some people read this letter by letter. 😉
I need to check if an arbitrary element of the “msg” array exist, not just msg[2].
I can have something like:

string message = "abc;def";
str[] msg = message.Split( ';' );
string temp = msg[3] ? msg[3] : "Failed";

in the next message processing.

[/EDIT]

  • 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-06-09T22:54:11+00:00Added an answer on June 9, 2026 at 10:54 pm

    Perhaps you wanted:

    string temp = msgs.Length > 2 ? msgs[2] : "Failed";
    

    Edit:

    For checking any element, the same thing works:

    int index = 42;
    string temp = msgs.Length > index ? msgs[index] : "Failed";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following piece of code: $tests = array( array (a, b, c), array
All, Consider the following code: void func(void) { int a; printf (%d, a); }
Please consider the following piece of code, which throws three different exceptions (namely, System.Configuration.ConfigurationErrorsException
The project holding the code has all default MSVS2008 settings. Consider the following code
Consider following code public class City { public string Name { get { return
Consider following piece of code void foo( bool forwad ) { vector<MyObject>::iterator it, end_it;
Consider the following piece of Java code. int N = 10; Object obj[] =
Consider the following Java code: try{ // do something // this piece of code
Consider the following code which works great in all modern browsers. CSS: .container {
Consider following make: all: a b a: echo a exit 1 b: echo b

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.