Solved

Help with C# string literal

Posted on 2006-11-06
5
2,147 Views
Last Modified: 2008-01-09
Can anybody give me a quick run down of what this does;


header[header.Count - 1] += oneLine.TrimStart(new char[] {' ' /* dangerous ! */, '\t'});

I'm trying to convert an implementation of domainKeys to vb.net and I have no idea what is going on here. I get that on eof the param array is a tab - but what is going on before that?

It's only the TrimStart call I don't understand. What is going on?
0
Comment
Question by:thefritterfatboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17881545
The string stored in the last position in the array called header is having another string (oneLine) appended to it but only after any leading spaces or tabs have been trimmed off it.

TrimStart() will remove whitespace characters from the start of a string.
TrimStart(char[]) will remove any characters in the char[].
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 200 total points
ID: 17881553
for some reason someone has decided that trimming leading spaces is dangerous and had addeed a comment to that effect.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17881574
TrimStart(new char[] {' ', '\t'});

Result is string instance without leading spaces and tabs in original string. This means, if oneLine string contains any number of spaces and tabs in any order in the beginning, they are removed from result. BTW, I don't see anything dangerous here. For example , if oneLine is "   abc", this is executed as:

header[header.Count - 1] += "abc";

0
 
LVL 13

Expert Comment

by:joechina
ID: 17881625
Difference between
TrimStart(new char[] {' ', '\t'});
and
Trim();

is

Trim will remove new line and return as well

Try

string s = @"



aaa";

Console.WriteLine(s.Trim());

Console.WriteLine(s.TrimStart(new char[] {' ', '\t'}));

You will see the difference.

0
 
LVL 10

Author Comment

by:thefritterfatboy
ID: 17882305
It was the comment that had me there. I wasn't aware C# allowed for inline comments.

... I suspect the "danger" is to do with how the string is used in the encryption further down the script.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question