-6

I have this array:

enter image description here

And I need to make from array above string,one string like this:

(export_sdf_id=3746) OR (export_sdf_id=3806) OR (export_sdf_id=23) OR (export_sdf_id=6458) OR (export_sdf_id=3740) OR (export_sdf_id=3739) OR (export_sdf_id=3742)

Any idea what is the elegant way to implement it?

9
  • what defines whether or not a different array location is used? Commented Jan 28, 2016 at 10:16
  • Did you try searching? Please read How to Ask. Commented Jan 28, 2016 at 10:17
  • 1
    Why is someone voting to reopen? This question has been asked thousands of times before, and this question does not follow the guidelines found in How to Ask. There is no research shown. Commented Jan 28, 2016 at 10:24
  • 1
    here is the correct answer string result = String.Join(" OR ", idsArr.Select(x => '(' + x + ')')); Commented Jan 28, 2016 at 10:29
  • 5
    @Mark how about this one? Commented Feb 1, 2016 at 21:23

2 Answers 2

3

There is the String.Join-method designed for this.

var mystring = String.Join(" OR ", idsArr);

This will result in the following string:

export_sdf_id=3746 OR export_sdf_id=3806 OR export_sdf_id=23 OR export_sdf_id=6458 OR export_sdf_id=3740 OR export_sdf_id=3739 OR export_sdf_id=3742

Note that the brackets are omited as they are not needed for your query.

Sign up to request clarification or add additional context in comments.

1 Comment

you are missing brackets (x) or (y)...
2

You can use String.Join(String, String[]), where first parameter is separator between array elements.

string result = String.Join(" OR ", sArr);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.