cannot convert from 'System.StringSplitOptions' to 'char'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbewers1
    New Member
    • Feb 2009
    • 68

    cannot convert from 'System.StringSplitOptions' to 'char'

    I don't understand why I'm getting the following error in the last statement of this string of code:

    Code:
     string current = str.ReadLine();
                StringBuilder currentstr = new StringBuilder(fileName);
                
                //try and locate the details from within the file
                //do a substring search for these items - store whatever appears after = and before },
                PaperProperties prop = new PaperProperties();
                prop.Author1FirstName = current.Split("=", StringSplitOptions.RemoveEmptyEntries);
    Basically, what I'm trying to do is to split strings within each line of a document where there is an "=" sign present and remove any empty space around that "=" sign.

    I have tried placing a ToString() at the end of the method and changing the parameters of the Split() method, but neither are working. What can I do to eliminate this error? Should I be using a different class from StringBuilder?

    Cheers,
    Matt
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    YOu need to take another look at the overrides of a string.split
    Returns a string array that contains the substrings in this instance that are delimited by elements of a specified string or Unicode character array.


    There are four, and none of them are the (string, StringSplitOpti ons) that you are trying to send. Though the string[], StringSplitOpti ons might be converting your single string to an array of one element it's not wise to trust the framework to think for you. Either make a char[] or a string[] and send that.

    I assume that PaperProps.Auth or1FirstName is a string.
    String.split returns a string array string[]
    So trying to shove the entire returned string[] into a single string isn't going to work. You need to assign it a single element of the returned string[] such as

    Code:
    prop.Author1FirstName = current.Split(new char[]{'='})[0];
    current.Split(' =') will return a string[]
    [0] will be the first element of that array

    Try this short snippet to see what I mean
    Code:
    string current = "Bob=Author";
    string[] thelist = current.Split(new char[] {'='});
    string Author1FirstName = thelist[0];//breakpoint here to check the entire array
    MessageBox.Show(Author1FirstName, "Author");
    Last edited by tlhintoq; Feb 15 '10, 11:43 PM. Reason: remove whitespace in code

    Comment

    • mbewers1
      New Member
      • Feb 2009
      • 68

      #3
      Thanks

      Thanks for your detailed help

      Comment

      Working...