Keep String property after inseriting to a list - string

I´m doing a project where I need to recognize specific strings and add them to a list. Im using this method to insert them in a specific position:
insertAt(E,N,Xs,Ys) :-
same_length([E|Xs],Ys),
append(Before,Xs0,Xs),
length(Before,N),
append(Before,[E|Xs0],Ys)
The problem is that when I insert any String for example '4X',in my list appears 4X, as a number and a variable. How can i keep the single quotes after the insert?
This is the line that gives me problems:
insertAt('>500',0,ListA,ListB),writeln(ListB).
When the list show in promt it looks like [>500],without the quotes.

Simple example since you didn't indicate how you are creating 4X
test :-
append(["4x"],[],New),
write(New).
Example run:
?- test.
[4x]
true.
After updates in comments.
Is there a way to write while maintaining the quotes?
?- print('4x').
'4x'
true.
?- print([a,b,'4X',d]).
[a,b,'4X',d]
true.
Of note: portray/1
I have never used portray/1 but you might.

Related

Python3 strip() get unexpect result

It's a weird problem
to_be_stripped="D:\\Users\\UserKnown\\PycharmProjects\\ProjectKnown\\PT\\collections\\120"
And two strings below:
s1="D:\\Users\\UserKnown\\PycharmProjects\\ProjectKnown\\PT\\collections\\120\\[Content_Types].xml"
s2="D:\\Users\\UserKnown\\PycharmProjects\\ProjectKnown\\PT\\collections\\120\\_rels\.rels"
When I use the command below:
s1.strip(to_be_stripped)
s2.strip(to_be_stripped)
I get these outputs:
'[Content_Types].x'
'_rels\\.'
If I use lstrip(), they will be:
'[Content_Types].xml'
'_rels\\.rels'
Which is the right outputs.
However, if we replace all Project Known with zeus_pipeline:
to_be_stripped="D:\\Users\\UserKnown\\PycharmProjects\\zeus_pipeline\\PT\\collections\\120"
And:
s2="D:\\Users\\UserKnown\\PycharmProjects\\zeus_pipeline\\PT\\collections\\120\\_rels\.rels"
s2.lstrip(to_be_stripped)will be '.rels'
If I use / instead of \\, nothing goes wrong. I am wondering why this problem happens.
strip isn't meant to remove full strings exactly. Rather, you give it a string, and every character in that string is removed from the start and of the string to be stripped.
In your case, the variable to_be_stripped contains the characters m and l, so those are stripped from the end of s1. However, it doesn't contain the character x, so the stripping stops there and no characters beyond that are removed.
Check out this question. The accepted answer is probably more extensive than you need - I like another user's suggestion of using replace instead of strip. This would look like:
s1.replace(to_be_stripped, "")

How to remove white spaces and capitalize every first letter in the string in the robotramework

How can I remove white spaces and capitalize every first letter in the string in the robotframework, so later I use the result in the Selenium library calls?
Test to Unlock the Service Account:
Open Browser ${URL} ${Browser}
${string_1} = get text ${question_1}
${temp_answer} = set variable ${string_1}.title()
${answer}= evaluate ${string_1}.replace(" ","")
Input Text ${Answer_1} ${answer}
sleep 5s
Input:
Legal business name
Output:
LegalBusinessName?
You were close to achieving it, but made two crucial mistakes. The first one is you used Set Variable and tried calling the python's title() string method in the argument - but that doesn't work for the keyword. It is a straightforward assignment - synonymous to the = operator; so what you ended up with as value was the string "Legal business name.title()". You should use the Evaluate keyword like in the second call, which does python's code eval.
The other mistake was to use two different variables - you store the capitalized version in the var ${temp_answer}, but then you don't remove the whitespace from it, but from the original one - ${string_1}. So even if the capitalization worked, you still wouldn't get the desired end result in the ${answer} var.
Here's a one-liner how to achieve what you need:
${answer}= evaluate """${string_1}""".title().replace(" ","")
The 2 methods are chained - replace() works on the result of title(), and the value of string_1 is in triple quotes so python works with its sting representation.

Azure Logic App - simple condition to check for empty string variable fails

Solved
Issue was due to error in child action as Thomas pointed out, not the way I was checking the variable value.
I've got a variable that's been initialized earlier in the LA. Later on I'm trying to check if the variable is empty using a condition.
Here's the output from the run history:
It looks like the variable is an empty string at this point, however the condition fails without any helpful information.
I've also tried null or wrapping the variable in the empty command and comparing to true/false. All gave the same failure.
You can use the length function in the expression. I've found it helpful to also coallesce the value to an empty string before checking length.
For me placing an empty string between double quotes in a condition action to recognize the empty string works well.
Be aware however that once you enter the empty string in the condition action and save your logic app, if you afterwards go back in the designer and reopen the condition action the empty string enclosed in double quotes ("") is not displayed anymore.

How to save strings in matrixes in matlab

I want to have a matrix/cell, that has strings inside that I can access and use later as strings.
For instance, I have one variable (MyVar) and one cell (site) with names inside:
MyVar=-9999;
site={'New_York'; 'Lisbon'; 'Sydney'};
Then I want to do something like:
SitePosition=strcat(site{1},'_101'}
and then do this
save(sprintf('SitePosition%d',MyVar),);
This doesn't work at all! Is there a way to have strings in a matrix and access them in order to keep working with them if they were a string?
This:
MyVar=-9999; site={'New_York'; 'Lisbon'; 'Sydney'};
SitePosition = strcat(site{1},'_101');
save(sprintf('SitePosition%d',MyVar));
Works fine and yields SitePosition-9999.mat, note the syntax changes in lines 2 and 3.
Is there something else you're expecting?
EDIT: Based on your comment
Check out the documentation for save regarding saving specific variables
New example:
MyVar=-9999;
site={'New_York'; 'Lisbon'; 'Sydney'};
SitePosition = strcat(site{1},'_101');
save(SitePosition,'MyVar');
Creates New_York_101.mat with only the variable MyVar in it.

Prolog List of Constants to String

i have a list in input: [asd,qweqwe,fsdf,lkasd]
As un can see from the code i want connect each constant of the list to output a single variable list.
i m using yap prolog, i consult this code and i write :- run.
the write function print out _G1233 and not 'asd,asd2,asd3,asd4'
why ? how i have to change the code for output me 'asd,asd2,asd3,asd4' ?
run :- toAtomicVars([asd,asd2,asd3,asd4],',',Out),
write(Out),nl.
toAtomicVars([],In,Out).
toAtomicVars([A|B],In,Out) :-
atomic_concat(A,In,Out1),
atomic_concat(',',Out1,Out2),
toAtomicVars(B,Out2,Out2).
you (should) get a warning like
Singleton variables: [In,Out]
Singleton variables: [Out]
that means that you dont really do anything with those variables:
toAtomicVars([],In,Out).
In and Out can be anything, so prolog just prints a dummy value, _Gsomething that means that the variable is not instantiated.
same thing happens in the second clause:
toAtomicVars([A|B],In,Out) :-
atomic_concat(A,In,Out1),
atomic_concat(',',Out1,Out2),
toAtomicVars(B,Out2,Out2).
you dont say anywhere what is that Out.
personally i think that it would be easier if you just printed each variable recursively and then print a comma, something like:
print_list([X]):-
write(X).
print_list([H|T]):-
write(H),
write(', '),
print_list(T).
but if you want to put commas in the list you should add a rule that defines Out.

Resources