C# Argument 1: cannot convert from 'string' to 'char'












-3















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(@"");
}
}









share|improve this question

























  • 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


















-3















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(@"");
}
}









share|improve this question

























  • 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
















-3












-3








-3








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(@"");
}
}









share|improve this question
















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#






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 a string to a method that expects Char

    – 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 passed a string to a method that expects Char

    – 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














2 Answers
2






active

oldest

votes


















1














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);





share|improve this answer
























  • 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



















0














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





share|improve this answer


























  • 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











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
});


}
});














draft saved

draft discarded


















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









1














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);





share|improve this answer
























  • 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
















1














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);





share|improve this answer
























  • 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














1












1








1







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);





share|improve this answer













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);






share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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













0














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





share|improve this answer


























  • 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
















0














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





share|improve this answer


























  • 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














0












0








0







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





share|improve this answer















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






share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word