Skip to main content

All Questions

Tagged with
1186 votes
16 answers
1.6m views

How to convert UTF-8 byte[] to string

I have a byte[] array that is loaded from a file that I happen to known contains UTF-8. In some debugging code, I need to convert it to a string. Is there a one-liner that will do this? Under the ...
BCS's user avatar
  • 79.1k
304 votes
13 answers
383k views

How to access random item in list?

I have an ArrayList, and I need to be able to click a button and then randomly pick out a string from that list and display it in a messagebox. How would I go about doing this?
jay_t55's user avatar
  • 11.7k
538 votes
8 answers
527k views

.NET / C# - Convert char[] to string

What is the proper way to turn a char[] into a string? The ToString() method from an array of characters doesn't do the trick.
BuddyJoe's user avatar
  • 71.4k
388 votes
33 answers
866k views

Using C# to check if string contains a string in string array

I want to use C# to check if a string value contains a word in a string array. For example: string stringToCheck = "text1text2text3"; string[] stringArray = { "text1", "...
Theomax's user avatar
  • 6,828
211 votes
10 answers
604k views

Check if a value is in an array (C#)

How do I check if a value is in an array in C#? Like, I want to create an array with a list of printer names. These will be fed to a method, which will look at each string in turn, and if the string ...
Steven Matthews's user avatar
121 votes
10 answers
187k views

Is string in array?

What would be the best way to look in a string[] to see if it contains a element. This was my first shot at it. But perhaps there is something that I am overlooking. The array size will be no larger ...
Brad's user avatar
  • 21.3k
203 votes
13 answers
554k views

Checking if a string array contains a value, and if so, getting its position

I have this string array: string[] stringArray = { "text1", "text2", "text3", "text4" }; string value = "text3"; I would like to determine if stringArray contains value. If so, I want to locate its ...
MoShe's user avatar
  • 6,487
346 votes
5 answers
328k views

Convert array of integers to comma-separated string

It's a simple question; I am a newbie in C#, how can I perform the following I want to convert an array of integers to a comma-separated string. I have int[] arr = new int[5] {1,2,3,4,5}; I want to ...
Haim Evgi's user avatar
  • 126k
30 votes
8 answers
103k views

Pick Random String From Array

How do I go about picking a random string from my array but not picking the same one twice. string[] names = { "image1.png", "image2.png", "image3.png", "image4.png", "image5.png" }; Is this possible?...
atrljoe's user avatar
  • 8,161
8 votes
6 answers
67k views

Operator ‘==’ cannot be applied to operands of type ‘char’ and ‘string’

I’m working on a self directed simple program to practice concepts I’ve learned thus far. My project is related to chess, in this case specifically the board (columns a-h and rows 1-8). The user is ...
TargetofGravity's user avatar
243 votes
9 answers
483k views

convert string array to string

I would like to convert a string array to a single string. string[] test = new string[2]; test[0] = "Hello "; test[1] = "World!"; I would like to have something like "Hello World!"
user avatar
107 votes
3 answers
83k views

How can I safely convert a byte array into a string and back? [duplicate]

I don't really care about encoding and stuff, as long as I get back the exact same byte array. So to sum up: How do I convert a byte array into a string, and then that string back into the same byte ...
Svish's user avatar
  • 159k
74 votes
11 answers
236k views

C#: Limit the length of a string? [duplicate]

I was just simply wondering how I could limit the length of a string in C#. string foo = "1234567890"; Say we have that. How can I limit foo to say, 5 characters?
Lemmons's user avatar
  • 1,806
23 votes
12 answers
14k views

Is string actually an array of chars or does it just have an indexer?

As the following code is possible in C#, I am intersted whether string is actually an array of chars: string a="TEST"; char C=a[0]; // will be T
Kalamro's user avatar
  • 263
103 votes
3 answers
227k views

Split and join C# string [duplicate]

Possible Duplicate: First split then join a subset of a string I'm trying to split a string into an array, take first element out (use it) and then join the rest of the array into a seperate ...
Gaui's user avatar
  • 9,009

15 30 50 per page
1
2 3 4 5
8