#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    18
    Rep Power
    0

    Unhappy Property or indexer cannot be assigned to -- it's read only


    I'm writing a class to convert lower case letters to uppercase in C#.

    I've got;

    class Convert
    {
    private char[] Lalpha = new char[26];
    private char[] Ualpha = new char[26];

    public string UCase(string s)
    {
    for (int i = 0; i < 26; i++)
    {
    Lalpha[i] = (char) ('a' + i);
    Ualpha[i] = (char) ('A' + i);
    for (int j = 0; j < s.Length; j++)
    {
    if (Lalpha[i] == s[j])
    {
    s[j] = Ualpha[i];
    }
    }
    }
    return s;
    }
    }

    but when it comes to switching the lower case value with the uppercase one, "s[j] = Ualpha[i];" I get a line under 's[j]' along with the error;

    "Property or indexer 'string.this[int]' cannot be assigned to -- it is read only. "

    Can anyone help?

    Cheers.
    A.s
    Last edited by Brave Sir Robin; March 21st, 2004 at 11:50 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Redmond, WA
    Posts
    218
    Rep Power
    15
    Originally Posted by Brave Sir Robin
    I'm writing a class to convert lower case letters to uppercase in C#.
    There is an easier way to do this.

    Code:
    	public static string FirstLetterToUppercase( string str ) {
    	
    		string manipulatedString = String.Empty;
    		
    		if ( str.Length > 0 ) {
    			manipulatedString = str.Substring( 0, 1 ).ToUpper() + str.Substring( 1, str.Length - 1 ).ToLower();
    		} 
    	
    		return manipulatedString;
    	
    	}

    Originally Posted by Brave Sir Robin
    "Property or indexer 'string.this[int]' cannot be assigned to -- it is read only. "
    That means exactly what it says -- the indexer is read only, which means that it can only be read from, not written to.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    18
    Rep Power
    0
    Thanks for the shorter version.

    I'm just practicing at this point in time, but one thing is still bugging me. I tried putting the argument in a seperate veriable and then working with that but it still tells me it's read only.

    for instance

    public string UCase(string s)
    {
    string str = s;
    ...
    str[j] = Ualpha[i];
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Redmond, WA
    Posts
    218
    Rep Power
    15
    Originally Posted by Brave Sir Robin
    I'm just practicing at this point in time, but one thing is still bugging me. I tried putting the argument in a seperate veriable and then working with that but it still tells me it's read only.
    That's what it is. Read only.

    A string is an array of characters. You can't modify specific indexes.

IMN logo majestic logo threadwatch logo seochat tools logo