String.Trim is this correct functionality 
Author Message
 String.Trim is this correct functionality

Is there a bug with String.Trim?

When I try this code I get an unexpected result:-

string result  = "A   B A $ sign";
result = result.Trim('A');

I expected result to be "   B  $ sign" BUT I GET THIS "   B A $ sign" can
anyone explain this?

The MSDN help says:-

Removes all occurrences of a set of specified characters from the beginning
and end of this instance.

Overload List
Removes all occurrences of white space characters from the beginning and end
of this instance.

  [Visual Basic] Overloads Public Function Trim() As String
  [C#] public string Trim();
  [C++] public: String* Trim();
  [JScript] public function Trim() : String;
Removes all occurrences of a set of characters specified in a Unicode
character array from the beginning and end of this instance.

  [Visual Basic] Overloads Public Function Trim(ParamArray Char()) As String
  [C#] public string Trim(params char[]);
  [C++] public: String* Trim(__wchar_t __gc[]);
  [JScript] public function Trim(Char[]) : String;

If this is how it is meant to be then why?

Cheers

Ollie



Tue, 28 Dec 2004 16:09:50 GMT  
 String.Trim is this correct functionality
Hi,

"A   B A $ sign";

Read this sentance again. BEGINNING and END.

Quote:
> Removes all occurrences of a set of specified characters from the
beginning
> and end of this instance.

beginning - A
end - n(sig(n))

removes A form beginning
String doesn't end with A and nothing else will be removed.


Quote:
> Is there a bug with String.Trim?

> When I try this code I get an unexpected result:-

> string result  = "A   B A $ sign";
> result = result.Trim('A');

> I expected result to be "   B  $ sign" BUT I GET THIS "   B A $ sign" can
> anyone explain this?

> The MSDN help says:-

> Removes all occurrences of a set of specified characters from the
beginning
> and end of this instance.

> Overload List
> Removes all occurrences of white space characters from the beginning and
end
> of this instance.

>   [Visual Basic] Overloads Public Function Trim() As String
>   [C#] public string Trim();
>   [C++] public: String* Trim();
>   [JScript] public function Trim() : String;
> Removes all occurrences of a set of characters specified in a Unicode
> character array from the beginning and end of this instance.

>   [Visual Basic] Overloads Public Function Trim(ParamArray Char()) As
String
>   [C#] public string Trim(params char[]);
>   [C++] public: String* Trim(__wchar_t __gc[]);
>   [JScript] public function Trim(Char[]) : String;

> If this is how it is meant to be then why?

> Cheers

> Ollie



Tue, 28 Dec 2004 17:12:20 GMT  
 String.Trim is this correct functionality
cheers ok


Quote:
> Hi,

> "A   B A $ sign";

> Read this sentance again. BEGINNING and END.
> > Removes all occurrences of a set of specified characters from the
> beginning
> > and end of this instance.

> beginning - A
> end - n(sig(n))

> removes A form beginning
> String doesn't end with A and nothing else will be removed.



> > Is there a bug with String.Trim?

> > When I try this code I get an unexpected result:-

> > string result  = "A   B A $ sign";
> > result = result.Trim('A');

> > I expected result to be "   B  $ sign" BUT I GET THIS "   B A $ sign"
can
> > anyone explain this?

> > The MSDN help says:-

> > Removes all occurrences of a set of specified characters from the
> beginning
> > and end of this instance.

> > Overload List
> > Removes all occurrences of white space characters from the beginning and
> end
> > of this instance.

> >   [Visual Basic] Overloads Public Function Trim() As String
> >   [C#] public string Trim();
> >   [C++] public: String* Trim();
> >   [JScript] public function Trim() : String;
> > Removes all occurrences of a set of characters specified in a Unicode
> > character array from the beginning and end of this instance.

> >   [Visual Basic] Overloads Public Function Trim(ParamArray Char()) As
> String
> >   [C#] public string Trim(params char[]);
> >   [C++] public: String* Trim(__wchar_t __gc[]);
> >   [JScript] public function Trim(Char[]) : String;

> > If this is how it is meant to be then why?

> > Cheers

> > Ollie



Tue, 28 Dec 2004 16:39:51 GMT  
 String.Trim is this correct functionality

you would need something like this

string newString,testString,replaceString;

testString = "this is a test app to replace a";
replaceString = "a";

newString = testString.Replace(replaceString," ");

//this would trim or remove all occurences of a

hope this helps

Quote:
>-----Original Message-----
>Is there a bug with String.Trim?

>When I try this code I get an unexpected result:-

>string result  = "A   B A $ sign";
>result = result.Trim('A');

>I expected result to be "   B  $ sign" BUT I GET THIS "  
B A $ sign" can
>anyone explain this?

>The MSDN help says:-

>Removes all occurrences of a set of specified characters
from the beginning
>and end of this instance.

>Overload List
>Removes all occurrences of white space characters from

the beginning and end
Quote:
>of this instance.

>  [Visual Basic] Overloads Public Function Trim() As
String
>  [C#] public string Trim();
>  [C++] public: String* Trim();
>  [JScript] public function Trim() : String;
>Removes all occurrences of a set of characters specified
in a Unicode
>character array from the beginning and end of this
instance.

>  [Visual Basic] Overloads Public Function Trim

(ParamArray Char()) As String

- Show quoted text -

Quote:
>  [C#] public string Trim(params char[]);
>  [C++] public: String* Trim(__wchar_t __gc[]);
>  [JScript] public function Trim(Char[]) : String;

>If this is how it is meant to be then why?

>Cheers

>Ollie

>.



Tue, 28 Dec 2004 18:30:03 GMT  
 String.Trim is this correct functionality
What's the VB6 instr() function equivalent in C#?


: Hi,
:
: "A   B A $ sign";
:
: Read this sentance again. BEGINNING and END.
: > Removes all occurrences of a set of specified characters from the
: beginning
: > and end of this instance.
:
: beginning - A
: end - n(sig(n))
:
: removes A form beginning
: String doesn't end with A and nothing else will be removed.
:
:


: > Is there a bug with String.Trim?
: >
: > When I try this code I get an unexpected result:-
: >
: >
: > string result  = "A   B A $ sign";
: > result = result.Trim('A');
: >
: > I expected result to be "   B  $ sign" BUT I GET THIS "   B A $
sign" can
: > anyone explain this?
: >
: > The MSDN help says:-
: >
: > Removes all occurrences of a set of specified characters from the
: beginning
: > and end of this instance.
: >
: > Overload List
: > Removes all occurrences of white space characters from the beginning
and
: end
: > of this instance.
: >
: >   [Visual Basic] Overloads Public Function Trim() As String
: >   [C#] public string Trim();
: >   [C++] public: String* Trim();
: >   [JScript] public function Trim() : String;
: > Removes all occurrences of a set of characters specified in a
Unicode
: > character array from the beginning and end of this instance.
: >
: >   [Visual Basic] Overloads Public Function Trim(ParamArray Char())
As
: String
: >   [C#] public string Trim(params char[]);
: >   [C++] public: String* Trim(__wchar_t __gc[]);
: >   [JScript] public function Trim(Char[]) : String;
: >
: > If this is how it is meant to be then why?
: >
: >
: > Cheers
: >
: >
: > Ollie
: >
: >
: >
: >
:
:



Tue, 28 Dec 2004 23:20:28 GMT  
 String.Trim is this correct functionality
See the String class, IndexOf method.

-c


Quote:
> What's the VB6 instr() function equivalent in C#?



> : Hi,
> :
> : "A   B A $ sign";
> :
> : Read this sentance again. BEGINNING and END.
> : > Removes all occurrences of a set of specified characters from the
> : beginning
> : > and end of this instance.
> :
> : beginning - A
> : end - n(sig(n))
> :
> : removes A form beginning
> : String doesn't end with A and nothing else will be removed.
> :
> :


> : > Is there a bug with String.Trim?
> : >
> : > When I try this code I get an unexpected result:-
> : >
> : >
> : > string result  = "A   B A $ sign";
> : > result = result.Trim('A');
> : >
> : > I expected result to be "   B  $ sign" BUT I GET THIS "   B A $
> sign" can
> : > anyone explain this?
> : >
> : > The MSDN help says:-
> : >
> : > Removes all occurrences of a set of specified characters from the
> : beginning
> : > and end of this instance.
> : >
> : > Overload List
> : > Removes all occurrences of white space characters from the beginning
> and
> : end
> : > of this instance.
> : >
> : >   [Visual Basic] Overloads Public Function Trim() As String
> : >   [C#] public string Trim();
> : >   [C++] public: String* Trim();
> : >   [JScript] public function Trim() : String;
> : > Removes all occurrences of a set of characters specified in a
> Unicode
> : > character array from the beginning and end of this instance.
> : >
> : >   [Visual Basic] Overloads Public Function Trim(ParamArray Char())
> As
> : String
> : >   [C#] public string Trim(params char[]);
> : >   [C++] public: String* Trim(__wchar_t __gc[]);
> : >   [JScript] public function Trim(Char[]) : String;
> : >
> : > If this is how it is meant to be then why?
> : >
> : >
> : > Cheers
> : >
> : >
> : > Ollie
> : >
> : >
> : >
> : >
> :
> :



Tue, 28 Dec 2004 23:24:21 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Why am I not getting correct position?

2. Trim a comma off end of string???

3. Help to trim spaces of a string

4. trim the string

5. String.Trim() behavior

6. String.Trim();

7. Need help to trim spaces off a string

8. trimming a string

9. How to trim a string in a _variant_t

10. How to trim a String?

11. Right trim string function in C

12. trim for strings

 

 
Powered by phpBB® Forum Software