An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Hi @Scott Huang ,
Thanks for reaching out.
That error is caused by a small syntax issue in the if statement. In C#, the condition inside an if must be a complete Boolean expression enclosed in parentheses.
In your case, remove the comma after the IsUnicode(...) call and close the if condition properly:
if (IsUnicode(str31.Substring(cnt3a, 1)))
{
// your code here
}
The comma makes the compiler think the expression is not finished, so it keeps looking for the rest of the statement and reports ) expected.
Also, it is worth confirming that IsUnicode(...) returns a bool, since an if condition must evaluate to either true or false.
If there is any chance that str31 could be empty, null, or that cnt3a could be outside the string length, you may also want to guard against that to avoid a runtime error:
if (!string.IsNullOrEmpty(str31) && cnt3a >= 0 && cnt3a < str31.Length)
{
if (IsUnicode(str31.Substring(cnt3a, 1)))
{
// your code here
}
}
So the main fix is simply to remove the comma and make sure the parentheses are balanced.
Hope this helps! If my answer was also helpful to you, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.