How Do I Get First XX Words From A Variable?

kaybee123

Новичок
Регистрация
27.02.2014
Сообщения
7
Благодарностей
0
Баллы
1
Hey guys!

I've been digging the forums and the help and I can't find the answer to this!

I have a variable (It's a title):
"This is a long title post about cats and dogs" ---> Original variable

And I only want to take the first 5 words of the title to assign it to a new variable.
So... it would be:

"This is a long title" -------> This should be my new title

How should I be doing this?!?

Thanks! I'm stuck and I can't move forward in my project until I figure this out!
 

kaybee123

Новичок
Регистрация
27.02.2014
Сообщения
7
Благодарностей
0
Баллы
1
Anyone ? :o
 

Radzhab

Client
Регистрация
23.05.2014
Сообщения
1 500
Благодарностей
1 263
Баллы
113
C#:
 var s = "This is a long title post about cats and dogs";
            var line = "";
            var words = s.ToString().Split(' ').ToList().Take(5);
            foreach (var word in words)
            {
                line += word + " ";
            }

            line = line.Trim(); // This is a long title
 

Radzhab

Client
Регистрация
23.05.2014
Сообщения
1 500
Благодарностей
1 263
Баллы
113
Hardcore version
C#:
var s = "This is a long title post about cats and dogs";
string title = string.Join(" ",s.ToString().Split(' ').ToList().Take(5));
 
Последнее редактирование:

kaybee123

Новичок
Регистрация
27.02.2014
Сообщения
7
Благодарностей
0
Баллы
1
Oh, thank you! I know this is basic csharp but I don't code... so this is useful! thx
 

kaybee123

Новичок
Регистрация
27.02.2014
Сообщения
7
Благодарностей
0
Баллы
1
Ahhh if I can hire anyone to complete my bot/macro... I would do it.

Can I pay anyone here to finish this thing ?

Let me know!
 

Radzhab

Client
Регистрация
23.05.2014
Сообщения
1 500
Благодарностей
1 263
Баллы
113

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
Take your string and do a regex on it with \w+ with Matches No. 0-4 and put results to list. Do list processing and merge list items with string separator of {-String.Space-}
 

kaybee123

Новичок
Регистрация
27.02.2014
Сообщения
7
Благодарностей
0
Баллы
1

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)