Character recognition "-" Odd Behavior When Imported from Excel

Character recognition "-" Odd Behavior When Imported from Excel - The "-" is not recognized as expected when imported from excel - Messages

#1 Posted: 11/14/2022 6:20:01 PM
Ryan Freund

Ryan Freund

19 likes in 339 posts.

Group: User

I observed some unexpected behavior when using characters imported from excel. I have a "-" in the cell of an excel sheet which is imported into SMath. When I use this character in an if statement it does not find it to be equivalent to the "-" character in SMath. I'm guessing that it might have something to do with the cell format in excel, but I can't see what sort of information is following this character into SMath. Any idea what SMath is reading the two 'different' dashes "-" as?

Refer to the attached Smath File:

Steel Worksheet - Test.sm (9 KiB) downloaded 45 time(s).


Character Import Problem - Dash.jpg
#2 Posted: 11/15/2022 4:11:01 AM
Martin_B

Martin_B

21 likes in 84 posts.

Group: User

In Excel you used the charakter 2013 (hex), which is the short dash (en-dash): –
If you use the keyboard you will enter the charakter 002D, which is the "hyphen-minus": -

They only look very similar in SMath. But you can notice, that the hyphen-minus is slightly thicker.
#3 Posted: 11/15/2022 1:51:04 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

Hi. As MarB says, Excel have it's own things. This function could be useful to try to know what character it is, although it can be very slow if its unicode is large, in addition to also presenting inconveniences if the character is typed or pasted, which I do not understand well.

Steel Worksheet - uchar.sm (16 KiB) downloaded 50 time(s).

Clipboard01.png

Best regards.
Alvaro.
1 users liked this post
sergio 11/15/2022 4:04:00 PM
#4 Posted: 11/15/2022 6:06:35 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

There is another brute force option for character to unicode number - findstr().

The benefit of the approach is that once the search target is built, the search is reasonable fast (0.015 s), you only see it when the calculation runs without problems.

BTW, don't try to display S, this produces a soft crash in both versions.

Also, hovering over the definition of S produces a soft crash, due to the attempt to preview the contents.

uchar.sm (20 KiB) downloaded 51 time(s).
2022-11-15 21_55_01-SMath Solver - [Steel Worksheet - uchar.sm_].png
2022-11-15 22_17_29-SMath Solver 1.0.8253 - [uchar.sm].png
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
sergio 11/16/2022 6:00:00 AM
#5 Posted: 11/15/2022 7:36:25 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

Wrote

There is another brute force option for character to unicode number - findstr(). ...



Hi Martin. That's the technique adopted for this function here.

Clipboard01.png

Unfortunately N.256 requires some adjustment as it cannot properly save the characters less than 32.

However, I think that a function like uchar could be much more practical and stable in a C# plugin, perhaps in SpecialFunctions or some other similar.

Best regards.
Alvaro.
1 users liked this post
sergio 11/16/2022 6:00:00 AM
#6 Posted: 11/16/2022 4:46:26 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote



Hi Martin. That's the technique adopted for this function here.




I usually ignore forum posts without visual teaser

Yes, I agree, this would be a good candidate for an internal function.
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
Alvaro Diaz Falconi 11/16/2022 1:35:00 PM
#7 Posted: 11/16/2022 2:02:37 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1675 posts.

Group: User

Hi. Some notes about strings in SMath

Distribution: It could be that the functions for strings will be distributed in a dll strings.dll in the default SMath/plugins installation directory

Naming convention: All string function names have “str” somewhere, except concat, ucfirst ucwords, and few others. It would be interesting if all new functions also have "str" somewhere in the name.

Other functions to add:
- ascii and Unicode utilities, maybe returning vectors like Mathcad str2vec
- padding and stripping blanks
- comparisons between strings with options for case sensitive or not
- questions like strIsLetter or strIsNumber
- regular and expressions and matching patterns utilities
- base conversions
- ...

Best regards.
Alvaro.
#8 Posted: 11/16/2022 10:48:09 PM
Ryan Freund

Ryan Freund

19 likes in 339 posts.

Group: User

Thanks for all the replies, very helpful. Makes sense now.
#9 Posted: 3/3/2023 4:39:31 PM
⚜ Kenny Lemens, P.E. ᵂᴵ

⚜ Kenny Lemens, P.E. ᵂᴵ

74 likes in 164 posts.

Group: User

Greetings,

The following is a bit of a 'trick' that I just discovered: Smath will convert some of the characters within a string to its HEX value:
toDec(el(strsplit(substr(x,1,1),"\",2))
Where 'toDec() is a custom function that converts HEX string to a decimal, and the variable 'x' would be the character in question.

Below is the code for a working function (just copy and paste into your Worksheet):

Show Spoiler




Just be aware, this function is limited; there is no shortage of characters that will fail to return a result (This function will NOT work for Alphanumeric, Letters with Accents, Latin, etc.), some of which are shown below:

Show Spoiler



Since this function isn't guaranteed to return a result (but only takes 0.01sec), you could implement it as a precursory check to the more time-consuming UChar(x) method.


Hope this is of assistance,
-Kenny Lemens, P.E. ᵂᴵ
"No matter where you go, there you are." -Buckaroo BanzaiHotkeys: https://en.smath.com/forum/resource.ashx?a=45771&b=2
  • New Posts New Posts
  • No New Posts No New Posts