ADA : Convert an input with slashes to 3 seperate integers - string

How would I go about reading in an input that looks like "01/12/1997" to 3 seperate integers that are 01, 12, and 1997?

If using GNAT, you can use GNAT.String_Split, followed by the 'Value attribute conversion.

And just in case your question was an intermediate step on the way to parsing dates, you should take a look at GNAT.Calendar.Time_IO.Value which knows about parsing various dates formats.

I ended up adding 3 more variables, all strings. I then set them as Date(1..2) and Month(4..5) and Year(7..10), then I converted them all to integers and continued my program. Not the best way, but it worked.

Related

Dataflow - Azure - isDecimal

I have been trying to do a datatype check in a decimal column of a file by using the Data Flow from Azure Data Factory, but it is not working as expected. My issue is the following one:
I want to check if the number 121012132.12 is a decimal, so I am using the data flow's derived column and writing the expression: isDecimal('121012132.12', '17.2'). The output has always been false, even if I change the precision or replace a dot with a comma, etc. I have tried many different ways, but without success. I realized that if I shorten the number, it recognizes it as decimal. Moreover, If I try to convert it into decimal, it works well (toDecimal('121012132.12', 17, 2)
Please, can anyone tell me if there is a different way to do this check?
Thank you in advance
This happens because for decimal the precision is defaulted to (10,2).
try isFloat('121012132.12') this will work
Thanks
Hijesh

Way to find a number at the end of a string in Smalltalk

I have different commands my program is reading in (i.e., print, count, min, max, etc.). These words can also include a number at the end of them (i.e., print3, count1, min2, max6, etc.). I'm trying to figure out a way to extract the command and the number so that I can use both in my code.
I'm struggling to figure out a way to find the last element in the string in order to extract it, in Smalltalk.
You didn't told which incarnation of Smalltalk you use, so I will explain what I would do in Pharo, that is the one I'm familiar with.
As someone that is playing with Pharo a few months at most, I can tell you the sheer amount of classes and methods available can feel overpowering at first, but the environment actually makes easy to find things. For example, when you know the exact input and output you want, but doesn't know if a method already exists somewhere, or its name, the Finder actually allow you to search by giving a example. You can open it in the world menu, as shown bellow:
By default it seeks selectors (method names) matching your input terms:
But this default is not what we need right now, so you must change the option in the upper right box to "Examples", and type in the search field a example of the input, followed by the output you want, both separated by a ".". The input example I used was the string 'max6', followed by the desired result, the number 6. Pharo then gives me a list of methods that match that:
To get what would return us the text part, you can make a new search, changing the example output from number 6 to the string 'max':
Fortunately there is several built-in methods matching the description of your problem.
There are more elegant ways, I suppose, but you can make use of the fact that String>>#asNumber only parses the part it can recognize. So you can do
'print31' reversed asNumber asString reversed asNumber
to give you 31. That only works if there actually is a number at the end.
This is one of those cases where we can presume the input data has a specific form, ie, the only numbers appear at the end of the string, and you want all those numbers. In that case it's not too hard to do, really, just:
numText := 'Kalahari78' select: [ :each | each isDigit ].
num := numText asInteger. "78"
To get the rest of the string without the digits, you can just use this:
'Kalahari78' withoutTrailingDigits. "Kalahari"6
As some of the Pharo "OGs" pointed out, you can take a look at the String class (just type CMD-Return, type in String, hit Return) and you will find an amazing number of methods for all kinds of things. Usually you can get some ideas from those. But then there are times when you really just need an answer!

Convert string with commas into integer in Freemarker

I have a string with commas in between. How should I convert this string into an integer. I tried using
x?number
but that gives me the following error
Exceptionfreemarker.core.NonNumericalException
e.g. The string is "453,000". I need to convert this to 453000.
Is there any other way of doing this?
There's no function built in for parsing numbers with national formats. ?number only deals with computer format, because when numbers are transferred as strings (which should be already rare), that's what used to be used. So in principle x should be already a number when it gets to FreeMarker, or at least it should use computer format. If that's not possible, you will need a custom function (or method) for that.

Decoding Specification '(AA$)' For Write Statement

I'm confused as the what this write specification is trying to specify. N is an array of single characters. Could someone help me and explain the write format specification below. I saw someone post the exact same question a few days ago but the page is not there anymore.
WRITE(*,'(AA$)') N(I),","
The dollar sign in a format specifier suppresses a new line.
Therefore, the array N is written element-wise as a string (A) separated by a comma (second string A) one a single line.
Note that this syntax is not standard conforming, in modern Fortran you would write the format as
WRITE(*,'(2A)', advance='no') N(I),","

MATLAB line continuation within string

In MATLAB, ... is used to continue a line to the next line. But if I want to continue a long string within quotation, what can I do? ... will be treated as a part of the string itself.
Using [] is not a perfect solution since in most cases I use sprintf/fprintf to parse a long string like sql query. Using [] would be cumbersome. thanks.
If you put the string in brackets, you can build it in several pieces:
s = ['abc' 'def' ...
'ghi'];
You can then split that statement into several lines between the strings.
answer=['You can divide strings '...
,'by adding a comma '...
,'(as you probably know one year later).'];
You can use strcat or horzcat, which gives you somewhat more options than [], including the ability to mix in variables along with the hardcoded values.

Resources