All Questions
107 questions
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 ...
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?
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.
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", "...
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 ...
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 ...
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 ...
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 ...
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?...
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 ...
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!"
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 ...
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?
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
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 ...