Using split

Hi,

Can anyone tell me how to use split in case where i know where to start and cut to the end of text.

For example. Im startm on word “Community” and i dont know how long can it be whole phrase but i want to finish on the end of whole string.

Regards,
@fudi5

1 Like

HI @fudi5,

my understanding was from the string value you need last word right??

If yes

strValue.Split(" "c).Last.ToString()

Regards,
Arivu

1 Like

Hi @arivu96,

Not last word. I start split form"Community" and it finish on the end of whole string… there should be word1, word2, word3, word4 and last is word5 so split should finished after word5. There is nothing after word5.

I thing i need something like that: “Split(expression[,delimiter[,count]])”. Where count will be -1

Regards,
@fudi5

HI @fudi5,

Do your string will be like this
"word1, word2, word3, word4, word5 "

so you want “word5” as output right???
strValue.Split(","c).Last.ToString()

Regards,
Arivu

hi @arivu96,

Starting string: “word0 word1 word2 word3 word4 word5”
Start split from word0
And my output in this case: “word1 word2 word3 word4 word5”

Regards
@fudi5

Hi @fudi5,

Instead of split you can use replace function.

strValue.Replace("word0 ","")

Regards,
Arivu

Hi @arivu96,

I dont catch your advice. How can i use replace instead of split if i need part of string… i start split from word0 but this is not a first word in string… so thank but i found solution.

Solution is use split(strValue,“word0”,-1)

Regards
@fudi5

Hi @fudi5

Using Substring and IndexOf is probably a better bet than split in your case. (Unless you have to use split for some reason.)

StrValue.Substring(StrValue.IndexOf("Community"))

Like this:

Community.xaml (9.3 KB)

Regards
Troy

hi @tmays,

Yes there is a reason. This solution must be prepared for dynamic text so using indexOf in this case close this solution to one case…

Regards
@fudi5