val a = month(start_date),year(to-date) [closed] - scala

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a requirement, that I have a string like below input and I want string like below output. can anyone please help me ?
example 1
val input = "month(start_date),year(to_date),month(to_date)"
output = "start_date,to-date"
example 2
input = "abc(start),xyz(end)"
output = "start,end"

You need a regex to get the value inside parenthesis
val input = "month(start_date),year(to_date),month(to_date)"
val regex = "(?<=\\()[^)]+(?=\\))".r
val output = regex.findAllIn(input).toSet.mkString(",")
for regex explanation you can find it here How do I match the contents of parenthesis in a scala regular expression
toSet to remove the duplicated
and mkString to join the set with comma

Related

how to print substring between quotes in a string in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
such string:
interface Loopback0 description "Loopback Interface for network management" ip address 10.20.30.40 255.255.255.255 no ip proxy-arp
how to print what is between " "?
Loopback Interface for network management
Assuming that the " character occurs only 2 times or if you want the first pair:
# Get the indices of the " characters
ind1 = exampleStr.find('"')
ind2 = exampleStr.find('"', ind1+1)
# Get the substring between the two indices
result = exampleStr[ind1+1:ind2]

PowerShell Array issue with variable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am using Powershell and I have a variable like this:
$E = "Apple"
When I run $E[0] I expect to see Apple, but it shows A only. How can I do that?
$E = "Apple" Is not an array, it is a simple string declaration so when you try to get index 0 of that string (or char array) you are returning the first character in the character array:
0 1 2 3 4
[A] [P] [P] [L] [E]
The define an array you need a second item (separated by a comma):
$E = "Apple", "Orange"
Then you can use $E[0] to return Apple like you are wanting.

How to extract only version number from a string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am extracting oracle version from windows using powershell command and i get result as 10.2.0.3.0Patch2, however i need to extract only numeric value i.e. 10.2.0.3.0 (only version number). Any way we can do it ?
Version info extracted is =
10.2.0.3.0 Production, 10.2.0.3.0Patch2 Production, 10.2.0.5.0 Production, 11.2.0.4.0 Production
You can use a regular expression to extract a substring. Example:
"10.2.0.3.0Patch2" | Select-String '((?:\d{1,3}\.){4}\d{1,3})' | ForEach-Object {
$_.Matches[0].Groups[1].Value
}
# Outputs the string '10.2.0.3.0'
You can read more about regular expressions by reading the about_Regular_Expressions help topic:
PS C:\> help about_Regular_Expressions

How to give an alias name with a space in sparksql [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
i have tried below codes
trial-1
..........
val df2=sqlContext.sql("select concat(' ',Id,LabelName) as 'first last' from p1 order by LabelName desc ");
trial-2
.........
val df2=sqlContext.sql("select concat(' ',Id,LabelName) from p1 order by LabelName desc ");
val df3=df2.toDF("first last")
trial-1 is throwing error when i tried to run it.......but in trial-2 it is taking the command but throwing the error when i performed below action
scala> df3.write.parquet("/prashanth/a1")
When a SQL column contains special characters in a SQL statement, you can use `, such as `first last`.
You cannot use space in a Parquet column. You can either rename the column or use other file format, such as csv.

Detect letter where number was expected [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can I detect and show an error if someone put a letter and the program expects a number?
A regexp match makes this easy. Searching for any character which isn't a numeral or an arithmetic symbol:
if ( $input =~ /[^0-9+*/-]/ ) {
print "Incorrect character detected!\n"
}
Literally anything which is a letter:
if ( $input =~ /[A-Za-z]/ ) {
print "Incorrect character detected!\n"
}