-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (59 loc) · 1.92 KB
/
Copy pathProgram.cs
File metadata and controls
73 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections;
namespace TokenTweet
{
class Program
{
static void Main(string[] args)
{
string tweet = "Hello @ahmed, do you like #programming? # me and @saad love it. #python #hello_world ";
TweetToken(tweet);
}
public static void TweetToken(string str)
{
int i = 0;
ArrayList mentions = new ArrayList();
ArrayList hashtags = new ArrayList();
while (i < str.Length)
{
string currentTweet = "";
if (str[i] == '#')
{
if (str[i+1] != ' ')
{
i++;
int count = 0;
while (count < str.Length)
{
if (Char.IsLetterOrDigit(str[i]) || str[i] == '_')
{
currentTweet += str[i];
}
else if (Char.IsWhiteSpace(str[i]))
{
hashtags.Add(currentTweet);
break;
}
count++;
i++;
}
}
}
else if (Char.IsWhiteSpace(str[i]))
{
currentTweet += ' ';
}
i++;
}
Console.WriteLine("There are {0} hashtags", hashtags.Count);
foreach (var hash in hashtags)
{
Console.WriteLine("#"+ hash);
}
foreach (var men in mentions)
{
Console.WriteLine("@" + men);
}
}
}
}