C# Argument 1: cannot convert from 'string' to 'char'
I am trying to pull files in a directory where the selected path in the combo box item is selected.
I'm used to vb.net and when doing a split in C# I get error message below:
Argument 1: cannot convert from 'string' to 'char'
I want to get all the files and then for each file add the filename to a listbox.
Anyone can point me in the right direction or let me know what I am doing wrong in split.
Here is the code:
private void cbLogFileLocations_SelectedIndexChanged(object sender, EventArgs e)
{
string Files = Directory.GetFiles(cbLogFileLocations.SelectedItem.ToString());
foreach (string file in Files)
{
string strSplittedFileName = file.Split(@"");
}
}
c#
add a comment |
I am trying to pull files in a directory where the selected path in the combo box item is selected.
I'm used to vb.net and when doing a split in C# I get error message below:
Argument 1: cannot convert from 'string' to 'char'
I want to get all the files and then for each file add the filename to a listbox.
Anyone can point me in the right direction or let me know what I am doing wrong in split.
Here is the code:
private void cbLogFileLocations_SelectedIndexChanged(object sender, EventArgs e)
{
string Files = Directory.GetFiles(cbLogFileLocations.SelectedItem.ToString());
foreach (string file in Files)
{
string strSplittedFileName = file.Split(@"");
}
}
c#
You can post your code here in your question.
– Matthew Watson
Nov 21 '18 at 13:31
You passed astringto a method that expectsChar
– Panagiotis Kanavos
Nov 21 '18 at 13:32
add a comment |
I am trying to pull files in a directory where the selected path in the combo box item is selected.
I'm used to vb.net and when doing a split in C# I get error message below:
Argument 1: cannot convert from 'string' to 'char'
I want to get all the files and then for each file add the filename to a listbox.
Anyone can point me in the right direction or let me know what I am doing wrong in split.
Here is the code:
private void cbLogFileLocations_SelectedIndexChanged(object sender, EventArgs e)
{
string Files = Directory.GetFiles(cbLogFileLocations.SelectedItem.ToString());
foreach (string file in Files)
{
string strSplittedFileName = file.Split(@"");
}
}
c#
I am trying to pull files in a directory where the selected path in the combo box item is selected.
I'm used to vb.net and when doing a split in C# I get error message below:
Argument 1: cannot convert from 'string' to 'char'
I want to get all the files and then for each file add the filename to a listbox.
Anyone can point me in the right direction or let me know what I am doing wrong in split.
Here is the code:
private void cbLogFileLocations_SelectedIndexChanged(object sender, EventArgs e)
{
string Files = Directory.GetFiles(cbLogFileLocations.SelectedItem.ToString());
foreach (string file in Files)
{
string strSplittedFileName = file.Split(@"");
}
}
c#
c#
edited Nov 21 '18 at 13:43
Lennart
6,167125266
6,167125266
asked Nov 21 '18 at 13:29
BreauBreau
11
11
You can post your code here in your question.
– Matthew Watson
Nov 21 '18 at 13:31
You passed astringto a method that expectsChar
– Panagiotis Kanavos
Nov 21 '18 at 13:32
add a comment |
You can post your code here in your question.
– Matthew Watson
Nov 21 '18 at 13:31
You passed astringto a method that expectsChar
– Panagiotis Kanavos
Nov 21 '18 at 13:32
You can post your code here in your question.
– Matthew Watson
Nov 21 '18 at 13:31
You can post your code here in your question.
– Matthew Watson
Nov 21 '18 at 13:31
You passed a
string to a method that expects Char– Panagiotis Kanavos
Nov 21 '18 at 13:32
You passed a
string to a method that expects Char– Panagiotis Kanavos
Nov 21 '18 at 13:32
add a comment |
2 Answers
2
active
oldest
votes
You need to use single quotes if you are going to split on a character, so change to this:
//You have to escape the back slash or use the ampersand on the front
string strSplittedFileName = file.Split('\');
OR if you want to split using a string:
//When splitting by a string,
//you need to pass a string array and an Enum of StringSplitOptions
string strSplittedFileName = file.Split(new string { "\" }, StringSplitOptions.RemoveEmptyEntries);
I dont have enough reputation to vote up but thanks the first one helped. Cheers
– Breau
Nov 21 '18 at 13:43
@Breau No problem. Glad I could help.
– Ryan Wilson
Nov 21 '18 at 14:12
add a comment |
Please in the future make sure to include source code in post: the reason being that link rot happens etc and it's always nice to use as reference for people having the same issue as you.
As alluded to in a previous answer using the char representation in C# (string literals) will invoke the overload that accepts a char.
From: mystring.Split(@"")
To: mystring.Split('\')
If you are attempting to split by new lines rather use:
Environment.NewLineChar
Thanks for the info much appreciated.
– Breau
Nov 21 '18 at 13:58
Good luck Breau. Apologies that I didn't take time to compile before sending.
– Neal
Nov 21 '18 at 13:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413129%2fc-sharp-argument-1-cannot-convert-from-string-to-char%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to use single quotes if you are going to split on a character, so change to this:
//You have to escape the back slash or use the ampersand on the front
string strSplittedFileName = file.Split('\');
OR if you want to split using a string:
//When splitting by a string,
//you need to pass a string array and an Enum of StringSplitOptions
string strSplittedFileName = file.Split(new string { "\" }, StringSplitOptions.RemoveEmptyEntries);
I dont have enough reputation to vote up but thanks the first one helped. Cheers
– Breau
Nov 21 '18 at 13:43
@Breau No problem. Glad I could help.
– Ryan Wilson
Nov 21 '18 at 14:12
add a comment |
You need to use single quotes if you are going to split on a character, so change to this:
//You have to escape the back slash or use the ampersand on the front
string strSplittedFileName = file.Split('\');
OR if you want to split using a string:
//When splitting by a string,
//you need to pass a string array and an Enum of StringSplitOptions
string strSplittedFileName = file.Split(new string { "\" }, StringSplitOptions.RemoveEmptyEntries);
I dont have enough reputation to vote up but thanks the first one helped. Cheers
– Breau
Nov 21 '18 at 13:43
@Breau No problem. Glad I could help.
– Ryan Wilson
Nov 21 '18 at 14:12
add a comment |
You need to use single quotes if you are going to split on a character, so change to this:
//You have to escape the back slash or use the ampersand on the front
string strSplittedFileName = file.Split('\');
OR if you want to split using a string:
//When splitting by a string,
//you need to pass a string array and an Enum of StringSplitOptions
string strSplittedFileName = file.Split(new string { "\" }, StringSplitOptions.RemoveEmptyEntries);
You need to use single quotes if you are going to split on a character, so change to this:
//You have to escape the back slash or use the ampersand on the front
string strSplittedFileName = file.Split('\');
OR if you want to split using a string:
//When splitting by a string,
//you need to pass a string array and an Enum of StringSplitOptions
string strSplittedFileName = file.Split(new string { "\" }, StringSplitOptions.RemoveEmptyEntries);
answered Nov 21 '18 at 13:33
Ryan WilsonRyan Wilson
4,0391620
4,0391620
I dont have enough reputation to vote up but thanks the first one helped. Cheers
– Breau
Nov 21 '18 at 13:43
@Breau No problem. Glad I could help.
– Ryan Wilson
Nov 21 '18 at 14:12
add a comment |
I dont have enough reputation to vote up but thanks the first one helped. Cheers
– Breau
Nov 21 '18 at 13:43
@Breau No problem. Glad I could help.
– Ryan Wilson
Nov 21 '18 at 14:12
I dont have enough reputation to vote up but thanks the first one helped. Cheers
– Breau
Nov 21 '18 at 13:43
I dont have enough reputation to vote up but thanks the first one helped. Cheers
– Breau
Nov 21 '18 at 13:43
@Breau No problem. Glad I could help.
– Ryan Wilson
Nov 21 '18 at 14:12
@Breau No problem. Glad I could help.
– Ryan Wilson
Nov 21 '18 at 14:12
add a comment |
Please in the future make sure to include source code in post: the reason being that link rot happens etc and it's always nice to use as reference for people having the same issue as you.
As alluded to in a previous answer using the char representation in C# (string literals) will invoke the overload that accepts a char.
From: mystring.Split(@"")
To: mystring.Split('\')
If you are attempting to split by new lines rather use:
Environment.NewLineChar
Thanks for the info much appreciated.
– Breau
Nov 21 '18 at 13:58
Good luck Breau. Apologies that I didn't take time to compile before sending.
– Neal
Nov 21 '18 at 13:59
add a comment |
Please in the future make sure to include source code in post: the reason being that link rot happens etc and it's always nice to use as reference for people having the same issue as you.
As alluded to in a previous answer using the char representation in C# (string literals) will invoke the overload that accepts a char.
From: mystring.Split(@"")
To: mystring.Split('\')
If you are attempting to split by new lines rather use:
Environment.NewLineChar
Thanks for the info much appreciated.
– Breau
Nov 21 '18 at 13:58
Good luck Breau. Apologies that I didn't take time to compile before sending.
– Neal
Nov 21 '18 at 13:59
add a comment |
Please in the future make sure to include source code in post: the reason being that link rot happens etc and it's always nice to use as reference for people having the same issue as you.
As alluded to in a previous answer using the char representation in C# (string literals) will invoke the overload that accepts a char.
From: mystring.Split(@"")
To: mystring.Split('\')
If you are attempting to split by new lines rather use:
Environment.NewLineChar
Please in the future make sure to include source code in post: the reason being that link rot happens etc and it's always nice to use as reference for people having the same issue as you.
As alluded to in a previous answer using the char representation in C# (string literals) will invoke the overload that accepts a char.
From: mystring.Split(@"")
To: mystring.Split('\')
If you are attempting to split by new lines rather use:
Environment.NewLineChar
edited Nov 21 '18 at 13:45
answered Nov 21 '18 at 13:33
NealNeal
293111
293111
Thanks for the info much appreciated.
– Breau
Nov 21 '18 at 13:58
Good luck Breau. Apologies that I didn't take time to compile before sending.
– Neal
Nov 21 '18 at 13:59
add a comment |
Thanks for the info much appreciated.
– Breau
Nov 21 '18 at 13:58
Good luck Breau. Apologies that I didn't take time to compile before sending.
– Neal
Nov 21 '18 at 13:59
Thanks for the info much appreciated.
– Breau
Nov 21 '18 at 13:58
Thanks for the info much appreciated.
– Breau
Nov 21 '18 at 13:58
Good luck Breau. Apologies that I didn't take time to compile before sending.
– Neal
Nov 21 '18 at 13:59
Good luck Breau. Apologies that I didn't take time to compile before sending.
– Neal
Nov 21 '18 at 13:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413129%2fc-sharp-argument-1-cannot-convert-from-string-to-char%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can post your code here in your question.
– Matthew Watson
Nov 21 '18 at 13:31
You passed a
stringto a method that expectsChar– Panagiotis Kanavos
Nov 21 '18 at 13:32