Right $ value (string, 3)

I read through some kind of source code and came across what looks like a function call:

Right$(string, 3) 

I can understand that this is just simple string manipulation, but what is the meaning of the $ character?

+4
source share
5 answers

$ does not make sense in the context of the right function. In the ancient VB, Right $ was a feature in the new VB, this is correct, but you can also use Right $ (for backward compatibility)

Right$("hasan", 3) and Right("hasan", 3) same in VB.NET

This is just the convention used to refer to String-related functions.

+4
source

This is used to call the string function Right (), and not the variant function Right ().

 & -> Long % -> Integer # -> Double ! -> Single @ -> Decimal $ -> String 

The Right () function takes a "variant" as an input signal and returns a "variant". This is not optimal when used in strings. Using Right $ () takes a string and returns a string and therefore faster. Not sure if this is still true in VB.net

+3
source

This is a legacy of the old VB, that is, its string function. It was probably ported for backward compatibility.

+2
source

The $ sign was used to denote the type of the variable long, long ago in VB6 for both functions and variables . They were never recommended for variables, as they should always have been explicitly declared as follows:

 Dim myValue As String 

not a great practice:

 myValue$ = "" 

However, from time to time it was good practice to use some functions, such as the Right () function , which used the Type option . Variants can be variables of any type and are considered bad in terms of performance. When using strings with functions such as Right (), Left (), Mid (), etc., It would be better to be explicit and indicate that it was a string for performance reasons, as shown below:

 Right$(myValue, 3) 

The only exception to this practice was the Replace () function.

Now, the only reason it is stored in the Microsoft.VisualBasic .NET namespace is for grandfather or to convert VB6 code to VB.NET for compatibility reasons. There is no need to write new code using a notation indicating that you are using the String type with these functions.

Hope this helps!

+2
source

From wikipedia

The default type can be overridden for a particular declaration using a special variable name suffix character ( # for Double For Single , & for Long , % for Integer , $ for String and @ for Currency ). The same is true for the return type of the function.

In VB6, the Right function returns a variant, so in your example, it ensures that the Right function returns a string.

0
source

Source: https://habr.com/ru/post/1381726/


All Articles