I am doing some BDD but i've come across an issue i can't solve.
I am trying to write this as my gherkin line that's visible in the step defintions:
When the user has 2 overdue books where the fine is payed (fine is 0)
But the text comes out to
the user has {int} overdue books where the fine is payed \\(fine is {int})
i've tried to escape with a backslash in front of the character and stringified the integers but that just converts them to strings.
Cucumber is being helpful by suggesting what it thinks you might want your step definition to be. You don't have the follow it. This is also a valid cucumber-expression:
the user has 0 overdue books where the fine is payed \\(fine is 0)
Related
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!
I'm using beautiful soup to parse email invoices and I'm running into consistent problem involving special characters.
The text I am trying to parse is shown in the image.
But what I get from beautiful soup after finding the element and calling elem.text is this:
'Hi Mike, It=E2=80=\r\n=99s probably not a big drama if you are having problems separating product=\r\ns from classes. It is not uncommon to receive an order for pole classes and=\r\n a bottle of Dry Hands.\r\nAlso, remember that we will have just straight up product orders that your =\r\nsystem will not be able to place into a class list, hence having the extra =\r\nsheet for any =E2=80=9Cerroneous=E2=80=9D orders will be handy.'
As you can see the apostrophe is now represented by "=E2=80=99", double quotes are "=E2=80=9C" and "=E2=80=9D" and there are seemingly random newlines in the text, for example "product=\r\ns".
The newlines don't seem to appear in the image.
Apparently "E2 80 99" is the unicode hex representation of ' , but I don't understand why I can still see it in this form after having done email.decode('utf-8') before sending it to beautiful soup.
This is the element
<td border:="" class='3D"td"' left="" middle="" padding:="" solid="" style='3D"color:' text-align:="" v="ertical-align:">Hi Mike, It=E2=80=
=99s probably not a big drama if you are having problems separating product=
s from classes. It is not uncommon to receive an order for pole classes and=
a bottle of Dry Hands.
Also, remember that we will have just straight up product orders that your =
system will not be able to place into a class list, hence having the extra =
sheet for any =E2=80=9Cerroneous=E2=80=9D orders will be handy.</td>
I can post my code if required but I figure I must be making a simple mistake.
I checked out the answer to this question
Decode Hex String in Python 3
but i think that expects the entire string to be hex rather than just having random hex parts.
but I'm honestly not even sure how to search for "decode partial hex strings"
My final questions are
Q1 How do I convert
'Hi Mike, It=E2=80=\r\n=99s probably not a big drama if you are having problems separating product=\r\ns from classes. It is not uncommon to receive an order for pole classes and=\r\n a bottle of Dry Hands.\r\nAlso, remember that we will have just straight up product orders that your =\r\nsystem will not be able to place into a class list, hence having the extra =\r\nsheet for any =E2=80=9Cerroneous=E2=80=9D orders will be handy.'
into
'Hi Mike, It's probably not a big drama if you are having problems separating products from classes. It is not uncommon to receive an order for pole classes and=\r\n a bottle of Dry Hands.Also, remember that we will have just straight up product orders that your system will not be able to place into a class list, hence having the extra sheet for any "erroneous" orders will be handy.'
using python 3, without manually fixing each string and writing a replace method for each possible character.
Q2 Why does this "=\r\n" appear everywhere in my string but not in the rendered html?
#JosefZ's comment lead me to the answer.
Q1 has an answer.
>>> import quopri
>>> print(quopri.decodestring(mystring).decode('utf-8'))
Hi Mike, It’s probably not a big drama if you are having problems separating products from classes. It is not uncommon to receive an order for pole classes and a bottle of Dry Hands.
Also, remember that we will have just straight up product orders that your system will not be able to place into a class list, hence having the extra sheet for any “erroneous” orders will be handy.
Q2 Thanks to #snakecharmerb I now know that the seemingly random unrepresented line endings are to enforce a line length of 80 characters.
#snakecharmerb wrote a much better answer than this one to someone with the same problem as me here.
https://stackoverflow.com/a/55295640/992644
I am learning how to develop Skills with Alexa. I followed a Lynda course to build the My Calculator skill, however ran into a problem where the numbers and results are not returned. I double checked my code, and tried it on Echoism.io, and same problem.
Per the attached, the numbers are recorded in the JSON input, however are not returned in the speechText or displayText?
What is the missing piece of code? Thanks.
Node.js code
Alexa console JSON Input
Welcome Roy! Couple things. In the future just put your code right here on the page so that it becomes searchable and we can see the exact characters you are using.
By looking at the images it looks like to me the following might be your use of template literals. Super common mistake.
So to use template literals you need use the back tick (`) instead of the single quote (')
It looks like it is that you currently have
speechText = 'The result of ${firstNumber} plus ${secondNumber} is ${result}';
and what you want is
speechText = `The result of ${firstNumber} plus ${secondNumber} is ${result}`;
Here is another good resources:
How to interpolate variables in strings in JavaScript, without concatenation?
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),","
In my project I am developing teachers and their timetable. I was provided with a text file that contains the teacher timetable from my uni. They ware unable to tell me what is the syntax or code language so I would know how to read it and use it in my iPhone app. Can you help me identifying what sot of code is this and how can I read that?
Sample:
SEM1:3ENCE_B:NW:NG102:EECT300:120:0900:2
SEM1:3ENCE_B,3ENCE_C:TW:NLG107:EEEL300:120:0900:1
19:3ENCE_A,3ENCE_B,3ENCE_C:TW:CLG.01:EEEL305_L:120:1100:1
19:3ENCE_A,3ENCE_B,3ENCE_C:TW:NLG107:EEEL305:120:0900:1
SEM1:3ENCE_A,3ENCE_B:TW::EEEL300:120:1100:4
SEM1&2:3ENCE_A,3ENCE_B,3ENCE_C,3ENCE_D:SK:CLG.06:EEEL315_L:120:1400:4
SEM1:3CS_A,3CS_B,3CS_C,3CS_D,3ENCE_A,3ENCE_B,3ENCE_C,3ENCE_D:DHE:CLLT:EICG301_L:120:0900:5
SEM1:3CS_A,3CS_B:ABO,DHE:N5.114:EICG301:120:1100:5
SEM1:3CS_A,3CS_B,3CS_C,3CS_D,3ENCE_A,3ENCE_B,3ENCE_C,3ENCE_D:NW:LTS205:EECT300_L:120:1600:2
27:3ENCE_A,3ENCE_B,3ENCE_C,3ENCE_CS::NG100:EEEL320:120:1100:2
SEM1:3CS_A,3CS_B,3CS_C,3CS_D:NW:C2.14:ECSC302_L:120:0900:3
SEM1:3CS_A:NW:NG100:EECT300:120:1400:2
It's not code, it's data. And the best way of interpreting it is to compare this representation with another : Think Rosetta Stone.
Obviously, colon is used to separate the fields, and each line probably represents a single tinmetable item. Each line appears to have 8 fields on it.
One field looks like a course ID : EECT300
Another looks like a time : 0900
As for the rest, you'll have to work it out...
University of Westminster, maybe...?
It is not a code language.
It is just a plain text file which contains data using colons : as a separator
I guess you have to parse it and retrieve the information for each column. You have to be aware of the signification of each column (if no ask to your uni)