Trim/Erase/Replace

Hello Wonderfull people,
I would like you to help me understand the use of trim syntaxis.
Context:
i undersant that Trim 's function let us cut empty spaces (at the end or start of a string)
However i checked in previous forum notes that someone proposed this syntaxis to erase “"
String phrase : " Call me once you’re available ** " stored in Variable1
So that, to erase "
”, they used:
Variable1.trim({" “c,”*"c})
Here is my problem i dont understand the components inside ( ), why use c, and { ?
Thanks for any help
Ricchch

@Ricchch
The Trim function in this context is used to remove specific characters from the beginning and end of a string, rather than just empty spaces. The syntax you mentioned Variable1.Trim({" “c,”*"c}) is a bit different and has the following components:

  1. { } - This represents an array initializer or array literal in VB.NET. It allows you to specify a list of values enclosed in curly braces.
  2. " “c," - This is a string containing the characters you want to remove from the string. In this case, it includes the space character (" “) and the double quote character (”").
  3. "*c" - This is a string containing a wildcard character () followed by “c”. The wildcard character () is used to match any character.

When you pass this array of characters to the Trim function, it will remove all occurrences of those characters from the beginning and end of the string. In your example, it will remove spaces and double quotes from both ends of the string.

So, Variable1.Trim({" “c,”*"c}) will remove any leading or trailing spaces or double quotes from the string stored in Variable1.

1 Like

Hi @Ricchch

Usually we would use something like this to remove additional spaces and " from the string.
Variable1.Trim(" “”".ToCharArray)

For example
input: Variable1 has " Hey please call me back "
output would be Hey please call me back if you use the above expression

1 Like

Hi @Ricchch

  1. Variable1: This represents the variable name that holds the string value you want to modify. In your example, it is “Call me once you’re available **”.
  2. .Trim(): This is a method used to remove characters from the beginning and end of a string.
  3. {" ", "*"}: This is a character array enclosed in curly braces, denoting the characters you want to remove. In this case, it includes a space (" “) and an asterisk (”*"). The Trim() method will remove any leading or trailing occurrences of these characters from Variable1.
  4. “c”: The “c” inside the curly braces denotes that the array elements are characters. It is used to specify the type of the array elements. In this case, both " " (space) and “*” (asterisk) are characters.

Hope it helps!!

The parameters of the function must be character. But " " and "*" are string. Putting the c after the " " and "*" converts them to character datatype.

1 Like

Thanks @pravallikapaluri , @raja.arslankhan , @adiijaiin @postwick for helping me with this.
Really appreciated…
Ricchch

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.