~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Globals/StringHelpers.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created by SharpDevelop.
 
3
 * User: Peter Forstmeier
 
4
 * Date: 16.07.2011
 
5
 * Time: 19:46
 
6
 * 
 
7
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 
8
 */
 
9
using System;
 
10
 
 
11
namespace ICSharpCode.Reports.Core.Globals
 
12
{
 
13
        public class StringHelpers
 
14
                {
 
15
                        /// <summary>
 
16
                        /// Left of the first occurance of c
 
17
                        /// </summary>
 
18
                        /// <param name="src"></param>
 
19
                        /// <param name="c"></param>
 
20
                        /// <returns></returns>
 
21
                        public static string LeftOf(string src, char c)
 
22
                        {
 
23
                                int idx=src.IndexOf(c);
 
24
                                if (idx==-1)
 
25
                                {
 
26
                                        return src;
 
27
                                }
 
28
 
 
29
                                return src.Substring(0, idx);
 
30
                        }
 
31
 
 
32
                        /// <summary>
 
33
                        /// Left of the n'th occurance of c
 
34
                        /// </summary>
 
35
                        /// <param name="src"></param>
 
36
                        /// <param name="c"></param>
 
37
                        /// <param name="n"></param>
 
38
                        /// <returns></returns>
 
39
                        public static string LeftOf(string src, char c, int n)
 
40
                        {
 
41
                                int idx=-1;
 
42
                                while (n != 0)
 
43
                                {
 
44
                                        idx=src.IndexOf(c, idx+1);
 
45
                                        if (idx==-1)
 
46
                                        {
 
47
                                                return src;
 
48
                                        }
 
49
                                        --n;
 
50
                                }
 
51
                                return src.Substring(0, idx);
 
52
                        }
 
53
 
 
54
                        /// <summary>
 
55
                        /// Right of the first occurance of c
 
56
                        /// </summary>
 
57
                        /// <param name="src"></param>
 
58
                        /// <param name="c"></param>
 
59
                        /// <returns></returns>
 
60
                        public static string RightOf(string src, char c)
 
61
                        {
 
62
                                int idx=src.IndexOf(c);
 
63
                                if (idx==-1)
 
64
                                {
 
65
                                        return "";
 
66
                                }
 
67
                                
 
68
                                return src.Substring(idx+1);
 
69
                        }
 
70
 
 
71
                        /// <summary>
 
72
                        /// Right of the n'th occurance of c
 
73
                        /// </summary>
 
74
                        /// <param name="src"></param>
 
75
                        /// <param name="c"></param>
 
76
                        /// <returns></returns>
 
77
                        public static string RightOf(string src, char c, int n)
 
78
                        {
 
79
                                int idx=-1;
 
80
                                while (n != 0)
 
81
                                {
 
82
                                        idx=src.IndexOf(c, idx+1);
 
83
                                        if (idx==-1)
 
84
                                        {
 
85
                                                return "";
 
86
                                        }
 
87
                                        --n;
 
88
                                }
 
89
                                
 
90
                                return src.Substring(idx+1);
 
91
                        }
 
92
 
 
93
                        public static string LeftOfRightmostOf(string src, char c)
 
94
                        {
 
95
                                int idx=src.LastIndexOf(c);
 
96
                                if (idx==-1)
 
97
                                {
 
98
                                        return src;
 
99
                                }
 
100
                                return src.Substring(0, idx);
 
101
                        }
 
102
 
 
103
                        public static string RightOfRightmostOf(string src, char c)
 
104
                        {
 
105
                                int idx=src.LastIndexOf(c);
 
106
                                if (idx==-1)
 
107
                                {
 
108
                                        return src;
 
109
                                }
 
110
                                return src.Substring(idx+1);
 
111
                        }
 
112
 
 
113
                        public static string Between(string src, char start, char end)
 
114
                        {
 
115
                                string res=String.Empty;
 
116
                                int idxStart=src.IndexOf(start);
 
117
                                if (idxStart != -1)
 
118
                                {
 
119
                                        ++idxStart;
 
120
                                        int idxEnd=src.IndexOf(end, idxStart);
 
121
                                        if (idxEnd != -1)
 
122
                                        {
 
123
                                                res=src.Substring(idxStart, idxEnd-idxStart);
 
124
                                        }
 
125
                                }
 
126
                                return res;
 
127
                        }
 
128
 
 
129
                        public static int Count(string src, char find)
 
130
                        {
 
131
                                int ret=0;
 
132
                                foreach(char s in src)
 
133
                                {
 
134
                                        if (s==find)
 
135
                                        {
 
136
                                                ++ret;
 
137
                                        }
 
138
                                }
 
139
                                return ret;
 
140
                        }
 
141
                }
 
142
}