String Manipulations/Regex

Hi All,

Can someone help with an idea of how to proceed with this Please

I have a sentence: (successful) soccer (club(s)) (managers(abcd))

I want it in format of array as follows.
Arr[0] = successful Arr[1]=soccer , Arr[2]=club,Ar[3]=s , Arr[4] = managers , Arr [5]= abcd.

Later I want to generate sentences from the array .
Example words being in same order but some words can miss which will generate some array of strings again.

String1 = successful soccer clubs managers abcd.
String2 = Successful Soccer
string3 = clubs
string4 = managers
string5=successful managers
and so on

Can you please help with these two requests.
TIA

The following expression will work.

arrStr = System.Text.RegularExpressions.Regex.Matches(yourString,"\w+").Cast(Of System.Text.RegularExpressions.Match).Select(Function(m) m.Value).ToArray()

The latter will be solved by combination of array items.

Regards,

Hi @Yoichi

Thanks for the quick solution.

Is there a way i can generate all the combinations.The jumbling strings are not required just in the same order.No issue if some strings misses.I want all combinations.Can you please help.

Hi,

We can achieve it using recursive logic. How about the following?

Sample20230522-2L.zip (5.1 KB)

Regards,

Hi @Yoichi

Your logic produces all sets that are required but not in correct format.

How i need is If the string set was : (String1)(String2(String3))String4(String5)

Results should be combination of above but the strings should not change there postions.Examples as below.

1.String1
2.Strin2 String3
3.Strin2 String4 String5
4.String4 String5
5.String String5
6.string1 string2 string3 string4 string5

I hope my question is clear to you.

HI,

I suppose the above result fits your requirement.
Can you point which string in the result is wrong?

Regards,

Hi,

I observed all the combinations
They are in reverese order :frowning:
Successful should be the starting and so on and “abcd” should be last

I just understood your point. How about the following?

Sample20230522-2Lv2.zip (5.1 KB)

Regards,

1 Like

This Should be a lot lot helpful stuck for this kind of solutions for a week.I can proceed further now.

Thanks a lot @Yoichi

1 Like

Hi Yoichi Sorry for bothering you again.

From the list of combinations we got in the array.Is it possible that whenver a single charater “s” comes we remove the space before it and which adds the s to previous word.

For Example : This is a text s string.
Outcome : This is a texts string

want this to be applied for all the values in array

HI,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(targetString," (?=s\b)","")

Regards,

1 Like

Hi @Yoichi

How do i store the values in array again.From the above query?

Hi,

Can you try the following expression?

res = res.Select(Function(s) System.Text.RegularExpressions.Regex.Replace(s," (?=s\b)","")).ToArray()

Regards,

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.