I want to place my text so i can get something like:
"SomeText1
SomeText2 One ...
two ...
three ..."
And I need to customize each of sometexts and 1,2,3 separately.
So I use the code
Label{
...
textFormat: Text.RichText
text: <html><b><div style='font-size: 12pt;'> SomeText1</div></b></html>+
<html><i><div style='font-size: 12pt;'> SomeText2</div></i></html>+
(here must be a function which back some big text)
...
}
This code works great except one thing... It acts like ".simplefield()" and just "eat" all 2+ spaces and doesn't allow to use "\n". What can I do to change this?
I found the solution of my problem. When I type:
"1
2
3"
I see "1 2 3", but actually it is "1\n2\n3". My html-ed label doesn't react to "\n". So I just added a function in my .cpp, which replaced "\n" with "br". Here is it
str.replace("\n","<br>");
Related
So, im completely new to programming. All i know is extremely basic stuff like hello world. Basically, what i want to do is I want be able to pick random words out of a list. I'm not really sure how to do this. Im definitely not asking anyone to write the whole thing for me, I just need a starting point. Right now I'm pretty lost. Thanks in advance.
It does depend on how the list is "made".
If the list can be made by the programmer (thus static and not be altered by the user), you could do the following (copy and paste this into a .html file):
<html>
<button onclick="randomizeFunction()">Randomize!!</button>
<p>Random generated word is:</p>
<p id="randomWord"></p>
</html>
<script>
const myList = ["List item 1", "List item 2", "List item 3", "List item 4", "List item 5"];
randomizeFunction()
function randomizeFunction() {
document.getElementById("randomWord").innerHTML = myList[Math.floor(Math.random() * myList.length)]
}
</script>
Do note, this uses JavaScript as well! Most responsive websites are driven by it nowadays.
Javascript is the part between the script tags. For you to customize, change the items in const myList, between the [ ... ]. Make sure the [ ... ] stay and seperate items with a comma. Also, if you are to use words, make sure to quote them (making them strings), like I did.
By the way, most people don't mind to get their hands dirty and providing you with an example ('write the whole thing').
Keep going, programming is awesome!
You will need javascript for this rather than html.
I created a function for you, called Random Word Picker.
if you want to add javascript to a html page put it between these tags
<script> </script>
let theList = ["hello", "there", "john", "how", "are", "you", "doing"]
function randomWordPicker(aList){
let theListLength = theList.length / 10
let theAnswer = Math.floor( ( Math.random( ) * 10 ) * theListLength )
return aList[theAnswer]
}
let result = randomWordPicker(theList)
document.querySelector("h1").innerHTML = result
console.log(result)
this function will pick a random word from the list and then display it to a h1 tag and to the console.
I am using following code to try to get GUI elements from a function:
mypanelfn: func[] [
collect[
repeat i 10 [
print append copy "i in loop: " i
keep [t: text] keep append copy "message: " i
keep [field "entry"
button "Click" [t/text: "clicked"] return]]]]
view [
do [mypanelfn]]
There are no error messages and loop go on all right and a windows is also displayed. But this is only a small empty windows without any text, fields or buttons.
What is wrong with this code?
Edit: putting probe before collect shows (I have added line breaks for clarity):
[t: text "message: 1" field "entry" button "Click" [t/text: "clicked"] return
t: text "message: 2" field "entry" button "Click" [t/text: "clicked"] return
t: text "message: 3" field "entry" button "Click" [t/text: "clicked"] return
t: text "message: 4" field "entry" button "Click" [t/text: "clicked"] return
t: text "message: 5" field "entry" button "Click" [t/text: "clicked"] return
This method does not require setting any variables—it works by containing each iteration of faces within a common parent (panel):
view collect [
keep [below space 0x0]
repeat i 10 [
keep compose/deep [
panel [
origin 0x0
text (rejoin ["Message Number: " i])
field "entry"
button "Click" [face/parent/pane/1/text: "clicked"]
]
]
]
]
face/parent is the panel face whose first child (pane/1) is the text box (origin does not create a face).
You don't necessarily need the function there, however:
view mypanelfn
Works.
Note: the equivalent code in Rebol requires layout: view layout mypanelfn
The reason this happens is because view processes blocks! (anything inside []). So you don't have to do it.
In general, it's better to think of Red as a functional, message passing language. Everything is an expression, in contrast to imperative languages with procedures and statements.
once again; you need unique names for elements you want to address. Here a solution with reduce instead of compose
mypanelfn: func[] [
collect[
repeat i 10 [
tname: to-word rejoin ['t i]
print append copy "i in loop: " i
keep reduce [to-set-word tname 'text] keep append copy "message: " i
keep reduce [
'field "entry" 'button "Click" reduce [
to-set-path reduce [
tname 'text ]
"clicked" ]
'return ] ] ] ]
I recommend that you use the commands in the console to see what they do. E.g.
rejoin ['t i] creates a string "t1"with t and the (reduced/get-)value of i.
to-word changes that to a Red(bol) word t1
to-setword tname creates a set-word t1:
to-set-path reduce [tname 'text ]creates a set-path t1/text:
this works for me in rebol/view:
lay: mypanelfn
insert head lay 'across
view layout lay
I think while you're learning this stuff you need to look at the generated VID code to check that there are no problems before trying to View it.
After having asked this question in the DB section and being adived to ask it here, here is my problem:
I have the problem, that I have a long text that is being read from a database. The text itself is just a one liner. The problem is that it needs to be broken at exactly 80 chars even when in the middle of a word.
HTML or other languages will make the line break if the next word doesn't fit in the remaining chars and that is not what I want. The pages are done in jsf.
For example:
textarea= cols: 8 rows: 3
input= break these texts
normal:
break
these
texts
what I need:
break th
ese text
s
Any ideas on how I can do this?
you can use the below function just pass the string (you want to brake after every 80 char) to the function
function breakText(str)
{
i=0;
outputStr="";
str= str.replace(/(\r\n|\n|\r)/g," ");
while(i<str.length)
{
outputStr += str.substr(i,80) +"<br>"; // replace br with any line break you want
i=i+80;
}
return outputStr
}
NOTE : this function will replace all the line break and insert a <br> after every 80 char
Working DEMO
I am using pgfsweave with Lyx 1.6.8 and xtable.
providing table captions by
<<result=tex>>=
print(xtable(<dataframe>,caption="Here is my caption"))
#.
How can I insert a label into the table caption that I can crossreference in the text from the lyx>Insert>Cross-reference menu?
I have tried to insert>float>table and inserted
print(xtable(<dataframe>,floating=FALSE)) and
"Here is my caption" in the Table caption inner frame
but this results in (literally):
[float Table:
<...Table ...>
[Table 2: "Here is my caption" ] ]
Even a barefoot workaround to crossreference
<<result=tex>>=
print(xtable(<dataframe>,caption="Here is my caption",label = "tab:one"))
#
from an ERT-box would help.
SOLVED:
Just use TWO arguments in the xtable-function call in the R-code:
xtable(<dataframe>
, caption = "My caption\\label{tab:MyTable1}"
,label="tab:MyTable1")
The \\label{tab:MyTable1} inside the caption is changed to
\label{tab:MyTable1} by R and then interpreted by LaTeX.
The argument label="tab:MyTable1" is ignored by R and therefore at your disposal to trick Lyx into allowing for crossreferencing to the label table label.
Use Insert>label to insert the label "tab:MyTable1" (excluding the quotes) here.
I wrote a AS3 script, i have 2 fields to validate, i.e email and name.
For email i use:
function isValidEmail(Email:String):Boolean {
var emailExpression:RegExp = /^[a-z][\w.-]+#\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return emailExpression.test(Email);
}
How about name field? Can you show me some sample code?
EDIT:
Invalid are:
blank
between 4 - 20 characters
Alphanumeric only(special characters not allowed)
Must start with alphabet
I think you probably want a function like this:
function isNameValid(firstname:String):Boolean
{
var nameEx:RegExp = /^([a-zA-Z])([ \u00c0-\u01ffa-zA-Z']){4,20}+$/;
return nameEx.test(firstname);
}
Rundown of that regular expression:
[a-zA-Z] - Checks if first char is a normal letter.
[ \u00c0-\u01ffa-zA-Z'] - Checks if all other chars are unicode characters or a space. So names like "Mc'Neelan" will work.
{4,20} - Makes sure the name is between 4 and 20 chars in length.
You can remove the space at the start of the middle part if you don't want spaces.
Hope this helps. here are my references:
Regular expression validate name asp.net using RegularExpressionValidator
Java - Regular Expressions: Validate Name
function isNameValid(firstname:String):Boolean
{
var nameEx:RegExp = /^([a-zA-Z])([ \u00c0-\u01ffa-zA-Z']){4,20}+$/;
return nameEx.test(firstname);
}
{4,20} instead {2,20}
Problem avoided for names like Ajit