Split Array if comma is found - powershell

$FruitArray[0] = "Banana, Orange, Peach, Mangoes"
$FruitArray[1] = "Apple, Banana"
$FruitArray[2] = "Peach"
$FruitArray[3] = "Mangoes"
How to split the array items to get the following results?
$FruitArray[0] = "Banana"
$FruitArray[1] = "Orange"
$FruitArray[2] = "Peach"
$FruitArray[3] = "Mangoes"
$FruitArray[4] = "Apple"
$FruitArray[5] = "Banana"
$FruitArray[6] = "Peach"
$FruitArray[7] = "Mangoes"

Split the array elements at commas and assign the result back to the variable.
$FruitArray = $FruitArray -split ',\s*'

Related

How to combine two ClosedRange in Swift?

I am learning Quick Sort in swift and need to compose a complicated array.
Here is the code:
var arrayOne = 1...500
var arrayTwo = 501...1000
var array_one = arrayOne.reversed()
var array_two = arrayTwo.reversed()
var array = arrayOne + arrayTwo
I want to combine arrayOne + arrayTwo to array.
I can not use the + operator, Xcode tips me
Binary operator '+' cannot be applied to two
'CountableClosedRange' operands
I know how to get it by using for loops.
Elegant way is really needed. Such as Higher order function.
1...500 is a range and (1...500).reversed() is a collection. Both are sequences so that you can append them to an array:
let rangeOne = 1...500
let rangeTwo = 501...1000
let array = [] + rangeOne.reversed() + rangeTwo.reversed()
// [500, 499, ..., 2, 1, 1000, 999, ..., 502, 501]
Alternative solutions are:
let array = Array(rangeOne.reversed()) + rangeTwo.reversed()
let array = Array([rangeOne.reversed(), rangeTwo.reversed()].joined())
let array = Array(rangeOne.reversed()) + Array(rangeTwo.reversed())
let array = [rangeOne.reversed(), rangeTwo.reversed()].flatMap { $0 }

Random selection of a member's location in a nested cell of cells: Matlab

I have a nested cell of cells like the one below:
CellArray={1,1,1,{1,1,1,{1,1,{1,{1 1 1 1 1 1 1 1}, 1,1},1,1},1,1,1},1,1,1,{1,1,1,1}};
I need to randomly pick a location in CellArray. All members' locations of CellArray must have same chances to be chosen in the random selection process. Thanks.
You can capture the output of the celldisp function. Then use regex to extrcat indices:
s=evalc('celldisp(CellArray,'''')');
m = regexp(s, '\{[^\=]*\}', 'match');
Thanks to #excaza that suggested a clearer use of regexp
Result:
m =
{
[1,1] = {1}
[1,2] = {2}
[1,3] = {3}
[1,4] = {4}{1}
[1,5] = {4}{2}
[1,6] = {4}{3}
[1,7] = {4}{4}{1}
[1,8] = {4}{4}{2}
[1,9] = {4}{4}{3}{1}
[1,10] = {4}{4}{3}{2}{1}
[1,11] = {4}{4}{3}{2}{2}
[1,12] = {4}{4}{3}{2}{3}
[1,13] = {4}{4}{3}{2}{4}
[1,14] = {4}{4}{3}{2}{5}
[1,15] = {4}{4}{3}{2}{6}
[1,16] = {4}{4}{3}{2}{7}
[1,17] = {4}{4}{3}{2}{8}
[1,18] = {4}{4}{3}{3}
[1,19] = {4}{4}{3}{4}
[1,20] = {4}{4}{4}
[1,21] = {4}{4}{5}
[1,22] = {4}{5}
[1,23] = {4}{6}
[1,24] = {4}{7}
[1,25] = {5}
[1,26] = {6}
[1,27] = {7}
[1,28] = {8}{1}
[1,29] = {8}{2}
[1,30] = {8}{3}
[1,31] = {8}{4}
}
Use randi to select an index:
m{randi(numel(m))}

PowerShell accessing data from hashtable inside hashtable

I have 5 hash tables:
$Monday = #{RUG = "";NRH1 = "";NRH2 = "";ELM = "";BAGVAGT = ""}
$Tuesday = #{RUG = "";NRH1 = "";NRH2 = "";ELM = "";BAGVAGT = ""}
$Wednesday = #{NRH1 = "";NRH2 = "";ELM = "";BAGVAGT = ""}
$Thursday = #{NRH1 = "";NRH2 = "";ELM = "";BAGVAGT = ""}
$Friday = #{NRH1 = "";NRH2 = "";ELM = ""}
That get filled with data. And I can get data out from these either one at at time with $Monday.RUG or all with $Monday | out-string. No problem there.
I'm going to combine those in another hash table 100 times with different data.
So it will be like this:
$Week = #{
1 = #{mo=$Monday;tu=$Tuesday;we=$Wednesday;th=$Thursday;fr=$Friday;val=$value}
2 = #{mo=$Monday;tu=$Tuesday;we=$Wednesday;th=$Thursday;fr=$Friday;val=$value}
}
And so on, until I have 100 different weeks with different values (value will be a calculated number)
But the question is. How do I access the items in the hashtables inside the $week hashtable?
Is there a direct way like $week.1.mo ? or do you need to use a loop?
You can access it using:
$Week[1].mo

Crystal Reports select expert OR statement on CSV

I am using the Select Expert to filter on a combination of 3 fields:
({flatfile_csv.site} = "L" and {flatfile_csv.bursguar} = "1")
or
({flatfile_csv.site} = "L" and {flatfile_csv.bursnorm} = "1")
In this case it only matches:
({flatfile_csv.site} = "L" and {flatfile_csv.bursguar} = "1")
If I swap the statements around:
({flatfile_csv.site} = "L" and {flatfile_csv.bursnorm} = "1")
or
({flatfile_csv.site} = "L" and {flatfile_csv.bursguar} = "1")
Then it only handles
({flatfile_csv.site} = "L" and {flatfile_csv.bursnorm} = "1")
It seems to completely ignore the second part of the OR statement. Any idea how to implement an OR in CR?
I've never used CR with a CSV file before, so I don't know how it's handling those empty strings. Try setting the selection formula to "Default Values for Nulls" instead of "Exception for Nulls" with this:
{flatfile_csv.site} = "L"
and
(
{flatfile_csv.burnsnorm}="1"
or {flatfile_csv.burnsguar}="1"
)

filemaker implode array

So lets say my calculation is this
Let (
[
$result[1] ="1";
$result[2] ="!";
$result[3] = "3";
$result[4] = "4";
$result[5] = "5";
$result[6] = "6";
$result[7] = "7";
$result[8] = "8";
$result[9] = "-";
$result[10] = "10";
$result[11] = "11";
$result[12] = "12";
$result[13] = "13";
$result[14] = "14";
$result[15] = "15";
$result[16] = "!";
];
$result[1] &
$result[2] &
$result[3] &
$result[4] &
$result[5] &
$result[6] &
$result[7] &
$result[8] &
$result[9] &
$result[10] &
$result[11] &
$result[12] &
$result[13] &
$result[14] &
$result[15] &
$result[16]
)
this is pretty straight forward I make and array and then I want to it to return the array as a string is there and easier way to concatenate the the values of the result array ?
** Sample custom functions ***
trying to use #chuck 's code not sure what I'm doing wrong I could figure out how to upload a file so here are some mimages
Here's two custom functions that should work if you can assume that once you get to a blank value in the array, you've reached the end of the array. I wrote it very quickly and only tested it once, but perhaps it'll do the job for you.
ConcatArray( VarName ) = _ConcatArray( VarName; 1 )
This just calls a recursive function with an initial value.
_ConcatArray( VarName; Iteration ) = Let(
[
Var = Evaluate( "$" & VarName & "[" & Iteration & "]" )
];
Case(
IsEmpty( Var );
"";
Var & _ConcatArray( VarName; Iteration + 1 )
)
)
I then opened the Data Viewer in FileMaker and tested it with this calculation.
Let (
[
$result[1] ="1";
$result[2] ="!";
$result[3] = "3";
$result[4] = "4";
$result[5] = "5";
$result[6] = "6";
$result[7] = "7";
$result[8] = "8";
$result[9] = "-";
$result[10] = "10";
$result[11] = "11";
$result[12] = "12";
$result[13] = "13";
$result[14] = "14";
$result[15] = "15";
$result[16] = "!"
];
ConcatArray( "result" )
)
The result was 1!345678-101112131415!.
You could do it with a recursive custom function. Specify the end range and the var name as parameters and it could then repeatedly call itself with an incrementing index number until that index number equaled the end range.