0

Can anyone say me why when using this block of code :

   StringBuilder temp = new StringBuilder(strSource);

                for (int i = Start; i <= End-1; i++)
                {
                    temp[i] = '';
                }

I get an error in the "for" loop: literal empty character.

On the other hand, this works:

temp[i] = ' ';
4
  • 1
    What is not clear about it? '' denotes a literal of type char, "" of type string. What would be the char you describe in =''? Commented Oct 5, 2014 at 14:29
  • 1
    On a sdie note i <= End-1 is the same as i < End Commented Oct 5, 2014 at 14:30
  • I just want to delete this char! Commented Oct 5, 2014 at 14:30
  • @ArnaudAd You can't delete characters this way, that's not how things work. Commented Oct 5, 2014 at 14:34

2 Answers 2

3

You're trying to reinvent the Remove method:

if (End > Start)
    temp.Remove(Start, End - Start);

'' is not valid because single quotes introduce a char literal, which must always be one char.

Sign up to request clarification or add additional context in comments.

Comments

0

Characters must have a value.

Instead, you should write

temp.Length = 0;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.