Regex for double in Hyperledger Modeling languager - hyperledger-fabric

Is there a way to validate currency in Hyperledger, I am aware that it is possible to validate String values using regex, but I get an error when using regex for Double data type.
Here is what gives an error, it complains about the one line in the Customer defination
participant Customer{
o Double balance regex=/^[0-9]+(\.[0-9]{1,2})?/
}
But this works (If the data type is String instead of Double)
participant Customer{
o String balance regex=/^[0-9]+(\.[0-9]{1,2})?/
}

Regular expressions are only valid for Strings in Composer.
Double, Long or Integer fields may include an optional range expression, which is used to validate the contents of the field.

Related

As String vs As String() in VBA [duplicate]

This may sound trivial, but what is the difference between
Dim v As String()
and
Dim v() As String
in VB.NET?
No difference. From the VB.NET Language Specification on Arrays:
Array types are specified by adding a modifier to an existing type name. The modifier consists of a left parenthesis, a set of zero or more commas, and a right parenthesis.
...
A variable may also be declared to be of an array type by putting an array type modifier or an array initialization modifier on the variable name. In that case, the array element type is the type given in the declaration, and the array dimensions are determined by the variable name modifier. For clarity, it is not valid to have an array type modifier on both a variable name and a type name in the same declaration.
Originally, in Basic, you had to define arrays, but not variables. And the types of variables were defined by a suffix character: A$ was a string, while A% was an integer and A# was double precision. (and all three were distinct and could be used at the same time) (For single-precision, you could use A!, but that was the default if you just used A)
Eventually, programmers came to realize that those were incredibly bad design choices.
To rectify this, Microsoft added "Option Explicit" which required you to predefine every variable. To lessen the effect on the language, they hijack the "DIM" command, which was used to define arrays, to define scalar variables as well.
So originally:
DIM A(50) ' define 51-element single-precision array
Then
DIM A(50) ' define 51-element single-precision array
DIM A$ ' define a string
Then to get rid of the suffixes, they added the "As {type} syntax"
DIM A(50) ' define 51-element single-precision array
DIM B as String
DIM C(50) as String ' define 51-element string array.
Then they made array size variable.
DIM A() ' define single-precision array
DIM B as String
DIM C() as String ' define string array.
This left a conflict in definition style, so they allowed both:
DIM A() ' define single-precision array
DIM B as String
DIM C() as String ' define string array.
DIM D as String() ' define string array.
There is no difference.
Both Dim v As String() and Dim v() As String will create a string array
Traditionally, in Basic, you would put the parenthesis after the variable name. In VB.Net it is allowed to put them after the type instead if you wish. The result is the same so there is no difference using either syntax. The reason for this addition though is because how you can constuct an array. Consider the following code:
Public Sub MethodThatExpectsAnArray(ByVal arr() As String)
'...
End Sub
Public Sub Main()
Me.MethodThatExpectsAnArray(New String() {"Hello", "World"})
End Sub
In the call I construct the array "on the fly" without any assignment except directly to the method argument. Since there are no variable here I must set the paranthesis after the type. To allow this syntax Microsoft had the choice to either change how you traditionally declare arrays in Basic or allow for both syntaxes. They of course opted for the latter.
There is no difference.
It's mostly semantics. The first reads as create variable "v" of type string array and the 2nd reads as create array "v" of type string. Either way the result is the same array of strings.
There is no difference in the meaning of the two.
If you like to declare several variables in one dim statement, the second form provides more flexibility:
dim v(),v2 as string allows you to declare array types and non array types in the same statement.

string(int), string(int32) and string([]int32) are all valid but string([]int) is invalid - what's the rationale here?

(I'm using Go 1.14.6.)
The following statements would all output the char a
Println(string(int(97) ) )
Println(string(int32(97) ) )
Println(string([]int32{97} ) )
But
Println(string([]int{97} ) )
would cause compile error
cannot convert []int literal (type []int) to type string
The behavior is confusing to me. If it handles string(int) the same as string(int32), why it handles string([]int) different from string([]int32)?
rune which represents a unicode code point is an alias for int32. So effectively string([]int32{}) is the same as string([]rune{}) which converts a slice of runes (something like the charaters of a string) to string. This is useful.
int is not int32 nor rune, so it's not logical what converting []int to string should be, it's ambiguous, so it's not allowed by the language spec.
Converting an integer number to string results in a string value with a single rune. Spec: Conversions:
Conversions to and from a string type
Converting a signed or unsigned integer value to a string type yields a string containing the UTF-8 representation of the integer. Values outside the range of valid Unicode code points are converted to "\uFFFD".
This is confusing to many, as many expects the conversion result to be the (decimal) representation as string. The Go authors have recognized this, and have taken steps to depcecate and remove it from the language in the future. In Go 1.15, go vet already warns for such conversion. Go 1.15 release notes: Vet:
New warning for string(x)
The vet tool now warns about conversions of the form string(x) where x has an integer type other than rune or byte. Experience with Go has shown that many conversions of this form erroneously assume that string(x) evaluates to the string representation of the integer x. It actually evaluates to a string containing the UTF-8 encoding of the value of x. For example, string(9786) does not evaluate to the string "9786"; it evaluates to the string "\xe2\x98\xba", or "☺".
Code that is using string(x) correctly can be rewritten to string(rune(x)). Or, in some cases, calling utf8.EncodeRune(buf, x) with a suitable byte slice buf may be the right solution. Other code should most likely use strconv.Itoa or fmt.Sprint.
This new vet check is enabled by default when using go test.
We are considering prohibiting the conversion in a future release of Go. That is, the language would change to only permit string(x) for integer x when the type of x is rune or byte. Such a language change would not be backward compatible. We are using this vet check as a first trial step toward changing the language.

Best way to compare multiple string in java

Suppose I have a string "That question is on the minds of every one.".
I want to compare each word in string with a set of word I.e. (to , is ,on , of) and if those word occurs I want to append some string on the existing string.
Eg.
to = append "Hi";
Is = append "Hello";
And so on.
To be more specific I have used StringTokenizer to get the each word and compared thru if else statement. However we can use Switch also but it is available in Jdk 1.
7.
I don't know if this is what you mean, but:
You could use String.split() to separate the words from your string like
String[] words = myString.split(" ");
and then, for each word, compare it with the given set
for(String s : words)
{
switch(s)
{
case("to"):
[...]
}
}
Or you could just use the String.contains() method without even splitting your string, but I don't know if that's what you wanted.
Use a HashMap<String,String> variable to store your set of words and the replacement words you want. Then split your string with split(), loop through the resulting String[] and for each String in the String[], check whether the HashMap containsKey() that String. Build your output/resulting String in the loop - if the word is contained in the HashMap, replace it with the value of the corresponding key in the HashMap, otherwise use the String you are currently on from the String[].

string variable returning as double

Create a method called parseEqn which will receive 1 String variable and return the double value of the expression passed to it.
parseEqn("123+23") → 146.0
parseEqn("3+5") → 8.0
parseEqn("3-5") → -2.0
so thats the question^^^^ and i think what i need to do is first use a string tokenizer to split the string up and then convert the tokens into doubles and from there add or subtract depending on the operator...but im not sure..
this is what i have so far
public double parseEqn(String str) {
StringTokenizer st = new StringTokenizer(str, "+-", true);
String first= st.nextToken();
String op= st.nextToken();
String second= st.nextToken();
double num1 = Double.parseDouble(first);
double num2 = Double.parseDouble(second);
if (op.equals("+")){
return num1+num2;
}
else (op.equals("-")){
return num1-num2;
}
i have no clue though....
Writing an expression parser is not a trivial task. The standard algorithm for parsing arbitrary infix expressions is the shunting-yard algorithm. The idea is to run through each token and build a Reverse Polish Notation (RPN) expression from the input. An RPN expression is essentially a stack-based list of operations that is very easy for a computer to work with (and easy to write code to evaluate).

How to convert string to int in linq to entity?

var trnlist = from tr in db.DebtorTransactions
join wr in db.Warranties
on tr.ProductID equals Convert.ToInt32(wr.PkfWarranty) into wrtd
from wr1 in db.Warranties
join sr in db.SalesReps
on wr1.fldSrId equals sr.pkfSrID into wrsr
from wr2 in db.Warranties
join ag in db.Agentsenter code here
on wr2.fldAgentID equals ag.pkfAgentID into wrag
select wrtd;
tr.ProductID is an int and wr.PKfWarranty is string.var rustul= convert.toint32(tr.ProductID) doesn't suitable for me.
Is there any built-in function of Linq to entity to do this?
Here you say:
tr.ProductID is a int
And then you try:
convert.toint32(tr.ProductID)
So... you're trying to convert an int to an int? In a comment you say:
the best overload method match for int.parse(string) has some invalid arguments
Well, if you're trying to call int.Parse() and passing it an int then you'd probably get that exact error. I imagine there's no overload for int.Parse() which accepts an int since, well, the value is already an int.
Let's look back at your problem description:
tr.ProductID is a int and wr.PKfWarranty is String
And you want to compare these two values? Then you'll either need to convert tr.ProductID to a string:
tr.ProductID.ToString()
or convert wr.PKfWarranty to an int:
int.Parse(wr.PKfWarranty)
A few things to note:
Converting from an int to a string is pretty safe, I doubt you'll ever have problems with that. However, converting from a string to an int assumes that the string can be converted to an int. This won't be the case if the string has anything in it that's not an int, or has a number too large to fit into the int data type. int.TryParse() exists for this purpose, but can be tricky to use in an in-line LINQ statement, especially when that statement is an expression tree which needs to produce SQL code.
If you convert the int to a string, there are different ways to compare strings. Depending on whether this is happening in resulting SQL code or in C# code makes a difference. If the latter, string.Equals() is the preferred method.

Resources