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.
Related
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
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
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 8 years ago.
Improve this question
I have an array in the third element dataArr[2], I know it contains a 10 digit phone. I need to only read or print the first 6 digits. For instance if my phone is 8329001111, I need to print out the 832900. I tried to see if I can use substr but I keep reading or printing the full list. Do I need to dereference..
Try this :
$dataArr[2] =~ s/\s//g; # ensure there's no spaces
print substr($dataArr[2], 0, 6);
# ^ ^ ^
# variable | |
# offset start|
# |
# substring length
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can someone explain what the second half of this script does? (second line)
$self is defined elsewhere... (I know what that part does, Just wondering what the action=~... is all about/)
$action = "http://example.com/test.php";
$action = $self->{url} . ($action =~ /^\// ? "" : "/" ) . $action;
It returns an empty string if $action starts with a slash, and a slash if it does not start with a slash.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In lex, I can define the following starting condition for equations defined between $...$.
%x EQN1
\$ { BEGIN(EQN1); }
<EQN1>{
\$ { BEGIN(INITIAL); }
[^\$]* {}
}
For equations between $$...$$, how can I define the anything but $$ rule, such as in [^\$]*. I guess [^\$\$]* wouldn't work.
I think you don't understand the way the patterns are matched, see flex manual
Flex always try to match longest input possible. You can understand it in way, that longer rules have higher priority.
Because "\$\$" match two characters and "." just one, the example below will work just fine.
%x EQN2
\$\$ { BEGIN(EQN2); }
<EQN2>{
\$\$ { BEGIN(INITIAL); }
. {}
}
You can also replace [^\$]* {} with . {} in your example, because when rules match same size of input, the first one in lex.l has higher priority.