I know the readLine() method, but if copy paste a text with more than one lines, only the first line will be retrieved.
I would like to retrieve all the text that the user copy pastes.
Is it possible ?
You can call readLine() in a loop and exit the loop in a predefined way
var input: [String] = []
print("Enter text, finish by entering Q")
while let line = readLine(strippingNewline: true) {
if line.lowercased() == "q" { break }
input.append(line)
}
print(input)
Example
Enter text, finish by entering Q
a
b
c
q
["a", "b", "c"]
Program ended with exit code: 0
Related
I have sample file record like this
2018-01-1509.05.540000000000001000000751111EMAIL#AAA.BB.CL
and the above record is from a fixed length file and I wanted to split based on the lengths
and when I split I am getting a list as shown below.
ListBuffer(2018-01-15, 09.05.54, 00000000000010000007, 5, 1111, EMAIL#AAA.BB.CL)
Everything looks fine until now . But I am not sure why is there extra-space adding in each field in the list(not for the first field).
Example : My data is "09.05.54",But I am getting as" 09.05.54" in the list.
My Logic for splitting is shown below
// Logic to Split the Line based on the lengths
def splitLineBasedOnLengths(line: String, lengths: List[String]): ListBuffer[Any] = {
var splittedLine = line
var split = new ListBuffer[Any]()
for (i <- lengths) yield {
var c = i.toInt
var fi = splittedLine.take(c)
split += fi
splittedLine = splittedLine.drop(c)
}
split
}
The above code take's the line and list[String] which are nothing but lengths as input and gives the listbuffer[Any] which has the lines split according to the length.
Can any one help me why am I getting extra space before each field after splitting ?
There are no extra spaces in the data. It's just adding some separation between the elements when printing them (using toString) to make them easier to read.
To prove this try the following code:
split.foreach(s => println(s"\"$s\""))
You will see the following printed:
"2018-01-15"
"09.05.54"
"00000000000010000007"
"5"
"1111"
"EMAIL#AAA.BB.CL"
I try to get stdin from readLine() in Swift, but the following two string to become the same one, but they should be different, while the latter one got more space.
//Console
abcd
abcd
//
let a = readline()!
let b = readline()!
print(a==b)
The second line from stdin got four more space in the end.
Is there any Swift api to solve this problem?
Consider the following code
val sc = new java.util.Scanner (System.in)
while (sc.hasNext()) {
var temp = sc.nextLine()
println(temp.nonEmpty)
println (temp)
}
whenever I press enter with empty line the program simply waits for next input to happen and does not execute the statement inside
For example
input:
<enter>
<enter>
1
cause
output:
<space>
false
<space>
false
1
true
I am trying to make user enter a list of lines, and exit on empty lines
eg.
1 2 3 4
5 6 7 8
<enter> // -> will exit
How would I achieve that?
I think this is a bit more idiomatic:
Iterator.continually(scala.io.StdIn.readLine).takeWhile(_.nonEmpty).foreach(line =>
println(s"read $line")
)
Add if (temp.isEmpty) sys.exit(1)
I have a file like this (10 000 lines):
"AAHA000","name1#domain.com"
"AAKA001","name2#domain.com"
"AALM001","name3#domain.com"
What I'm trying to do is to extract the email from the second part of each line when a match is found with the 7 character username.
Here is my current pseudocode. I can't really figure out how to extract the email from the textfile. I tried to use loopread but it did not work.
Userid:
Gui, Submit, NoHide
{
If (strlen(tuserid) = 7)
{
Search %textfile% for tuserid
If finds tuserid
{
Take the email from the same line and copy to %emailvariable%
Guicontrol,, Email, %emailvariable%
}
A file content loop and some regex will do the job. :)
inputFile = C:\My Data Textfile.txt
outputFile = C:\ExtractedEmails.txt
regex = ".+?","(.+?)"
Loop, read, %inputFile%, %outputFile%
{
RegexMatch(A_LoopReadLine, regex, match)
FileAppend, %match1%`r`n
}
How do I find all lines that begin with console in notepad++?
there can be zero to any number of spaces or tabs before the word console
suppose i have a file as follows:
'createdRow': function (row, data, index) {
console.log("data is: "); console.log(data);
fields=Object.keys(data)
console.log("fields is: "); console.log(fields);
noOfFields=fields.length
console.log("noOfFields is: "); console.log(noOfFields);
var highlightVal = 80;
var highlightClassName = 'highlight';
var counterIndexCount = 4;
for (var i=1; i <= counterIndexCount; i++) {
if (parseInt(data['counter'+ i].substring(0,2), 10) >= highlightVal) {
$('td', row).eq(i).addClass(highlightClassName);
} else {
$('td', row).eq(i).removeClass(highlightClassName);
}
}
I thought I might have to do something like \n console using the Extended option in the bottom left of the find search. But could not get it to work.
for my reference:
similar q asked here
Do a regex (regular expression) search for this:
^( |\t)*console
The ^ matches the start of the line; ( |\t)* matches any number of tabs or spaces; and console, of course, matches the text you're looking for.
If you want to match the whole line, add .* at the end:
^( |\t)*console.*
Type Ctrl+H
Then in the search window:
Find what: ^\s*console\b
then click on Find All in Current Document
You'll find the lines in the find result window.
^ : Begining of line
\s* : 0 or more any kind of space character
console : literally 'console'
\b : word boundary to make sure that is not matching 'consolefoobar'