本文整理汇总了C#中KacTalk.ktString.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ktString.GetValue方法的具体用法?C# ktString.GetValue怎么用?C# ktString.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KacTalk.ktString
的用法示例。
在下文中一共展示了ktString.GetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetPattern
// Set the pattern to use
public bool SetPattern(ktString Pattern)
{
RegexOptions Opt = new RegexOptions();
switch (m_Mode)
{
case ktRE_Mode.PERL:
{
ktString OPattern = new ktString(Pattern);
char Delim = Pattern.First();
Pattern.RemoveFirst();
int Pos = Find(Pattern, @"[^\\]" + Delim.ToString());
if (Pos < 0)
{
throw new ktError("ktRegEx::SetPattern() : The pattern isn't Perl compatible (" + OPattern + ")", ktERR.NOTFOUND);
}
else
{
Pos++;
}
ktString Modifiers = Pattern.SubStr(Pos + 1);
Pattern.Remove((uint)Pos);
for (uint I = 0; I < Modifiers.Len(); I++)
{
// Console.Write( Modifiers[I].ToString() + ";" );
switch (Modifiers[I])
{
case 'i':
{
Opt = Opt | RegexOptions.IgnoreCase;
break;
}
case 'm':
{
Opt = Opt | RegexOptions.Multiline;
break;
}
case 'x':
{
Opt = Opt | RegexOptions.IgnorePatternWhitespace;
break;
}
case 'A':
{
if (Pattern.First() != '^')
{
Pattern.Prepend("^");
}
break;
}/*
case 'i': {
Opt = Opt | RegexOptions.IgnoreCase;
break;
}*/
}
}
break;
}
case ktRE_Mode.Plain:
{
break;
}
default:
{
throw new ktError("ktRegExp::SetPattern(): The mode '" + GetModeAsString() +
"' is not implementet yet!",
ktERR.NOTIMP);
}
}
// Set the pattern
m_Pattern = Pattern;
// Take care of the (if any) exception
try
{
// Create the (internal) regex object
m_P = new Regex(m_Pattern.GetValue(), Opt);
}
catch (ktError Ex)
{
SetError("Couldn't set pattern and create a new (internal) Regex object" +
Ex.Message, ktERR.REGEX_COULDNT_SET_PATTERN);
return false;
}
catch (Exception Ex)
{
SetError("Couldn't set pattern and create a new (internal) Regex object" +
Ex.Message, ktERR.REGEX_COULDNT_SET_PATTERN);
return false;
}
return true;
}
示例2: Matches
// Match a pattern against a value (static!)
public static bool Matches(ktString Pattern, ktString Value, ktRE_Mode Mode)
{
// "Init" the object
Regex RegObj;
// Check which mode to use
// If we should use the mode "plain"
if (Mode == ktRE_Mode.Plain)
{
// Create the (internal) regex object using the givven pattern
RegObj = new Regex(Pattern.GetValue());
// Doesn't support the mode for now
}
else
{
// We set an error that we doesn't support the choosed mode
// (should we throw and exception???)
/*SetError( "ktRegExp::Match() : The mode '" + GetModeAsString().GetValue() +
"' is not implementet yet!",
ktERR.NOTIMP );*/
return false;
}
// Do the match...
return RegObj.IsMatch(Value.GetValue());
}
示例3: IsMatch
// Match a value against the storred pattern
public bool IsMatch(ktString Value, int Start)
{
// If we have a pattern?!
if ((m_Pattern.IsEmpty()) || (m_P == null))
{
// Set error (throw exeption??) and return false
SetError("ktRegExp::IsMatch(): The pattern is not set!", ktERR.NOTSET);
return false;
}
return m_P.IsMatch(Value.GetValue(), Start);
}
示例4: IsWord
// Check if the string Is one word (checks if it only include A-Z,a-z and any
// characters that may be added, default: '_' [underscore])
// OBS! This function doesn'T alowe spaces (even if it's added using 'AddedChars')
public bool IsWord(ktString AddedChars)
{
bool Res = true;
// We simply use IsAlpha() to check if it's valid
Res = IsAlpha(AddedChars.GetValue());
// If IsAlpha() OK'd the string
// Check for spaces...
if ((Res) && (Contains(" ")))
{
// Find space and that's not allowed...
Res = false;
}
return Res;
}
示例5: Matches
// Match and compare...
// Find, but with a mask (using ? and *)
public bool Matches(ktString Mask)
{
/* ** <note>
For now we just cross our fingers and hopes that this function (/method?)
actually works. We haven't runned this code yet.
(BTW this goes with most of the whole class...)</note>
***/
bool Match = false;
bool GoOn = true;
int Pos;
ktTripple Joker = 0; // 1 == * and 2 == ?
ktString MatchTmp;
ktString Str = new ktString(GetValue());
// Don't stop until we say so
while (GoOn)
{
Joker = 0;
// If there's no more "Joker"
if ((Pos = ktRegEx.Find(Mask.GetValue(), "\\*|\\?")) < 0)
{
// If (the rest of) the mask matches the string
if (Mask == Str)
{
// Stop looping
GoOn = false;
// And "OK it"
Match = true;
}
else
{
// Stop looping
GoOn = false;
// Didn' match...
Match = false;
}
}
else
{
// Find a "Joker" and get everything infront of it
MatchTmp = Mask.SubStr(0, Pos);
// Remove what we got from the mask
Mask.Remove(0, MatchTmp.Length());
// Chech the "Joker"
// If the first char is * in the "new mask"
// then indicate that
if (Mask.First() == '*')
Joker = 1;
// Or if it's ?...
else
Joker = 2;
// Remove the "Joker"
Mask.RemoveFirst();
// If this part of the mask doesn't match... (simply not a match)
if ((!MatchTmp.IsEmpty()) && (MatchTmp != Str.SubStr(0, MatchTmp.Length())))
{
// Stop looping
GoOn = false;
Match = false;
}
else
{
// As we now that this part of the mask matches the string
// Remove that part from the string
Str.Remove(0, MatchTmp.Length());
// If the "Joker" is *
if (Joker == 1)
{
// Get the position of the next "Joker"
Pos = ktRegEx.Find(Mask.GetValue(), "\\*|\\?");
// If we didn't find a new "Joker"
if (Pos < 0)
{
// get the length of the rest of the mask ("find the end")
Pos = Mask.Length();
// If Pos is 0
if (Pos == 0)
// No more mask...
Pos = -1;
}
// If Pos is less than 0
// This (should) means that the * was the last thing in
// the mask and should therefor match the rest of the string
if (Pos < 0)
{
// Stop looping
GoOn = false;
// It's a match...
Match = true;
//.........这里部分代码省略.........
示例6: BeforeLast
// Get string before the last occurence of the
// substring that Is supplied
public ktString BeforeLast(ktString Str)
{
// Get the position for the last occurence of 'Str'
int Pos = m_Content.LastIndexOf(Str.GetValue());
if (Pos < 0)
Pos = Length() - 1;
// Get everything before that occurence
return Left((uint)Pos);
}
示例7: Cmp
// Compare the string with 'Str' (ref. strcmp) (case-sensitive)
public int Cmp(ktString Str)
{
return String.Compare(Str.GetValue(), m_Content);
}
示例8: Append
// String value tampering
// Appends (concate, in the end) a string to the string
// returns a reference to the string
public ktString Append(ktString Str)
{
return Append(Str.GetValue());
}
示例9: BeforeFirst
// Get string before the First occurence of the
// substring that Is supplied
public ktString BeforeFirst(ktString Str)
{
// Get the position for the first occurence of 'Str'
int Pos = m_Content.IndexOf(Str.GetValue());
if (Pos < 0)
Pos = 0;
// Get everything before that position
return Left((uint)Pos);
}
示例10: Trim
// Trim the string (remove whitespaces etc, from the beginning and/or end)
public ktString Trim(ktStripType St, ktString WS)
{
if ((St == ktStripType.both) || (St == ktStripType.leading))
{
m_Content = m_Content.TrimStart(WS.GetValue().ToCharArray());
}
if ((St == ktStripType.both) || (St == ktStripType.trailing))
{
m_Content = m_Content.TrimEnd(WS.GetValue().ToCharArray());
}
return this;
}
示例11: Format
// Same as above but this function(s) returns the string
// instead of change the string in the object...
public static ktString Format(ktString Format, params object[] ParamList)
{
return new ktString(string.Format(Format.GetValue(), ParamList));
}
示例12: Strip
public ktString Strip(ktStripType St, ktString Delim)
{
string Str = m_Content;
if ((St == ktStripType.both) || (St == ktStripType.leading))
{
Str = Str.TrimStart(Delim.GetValue().ToCharArray());
}
if ((St == ktStripType.both) || (St == ktStripType.trailing))
{
Str = Str.TrimEnd(Delim.GetValue().ToCharArray());
}
return new ktString(Str);
}
示例13: SetValue
// Set the value of the string, from ktString format
public void SetValue(ktString Str)
{
if (((object)Str) == null)
{
m_Content = "";
}
else
{
m_Content = Str.GetValue();
}
}
示例14: Replace
// Replace First (or all) occurrences of substring with another one.
// (returns number of replacements)
public int Replace(ktString OldString, ktString NewString, bool ReplaceAll)
{
// Init Variables
int Count = 0;
string Tmp;
int Pos, tPos = 0;
// Get the first position
Pos = tPos = Find(OldString);
// Go on as long as we can find 'OldString'
while (tPos >= 0)
{
// Cut out everything before the 'OldString'
Tmp = m_Content.Substring(0, Pos);
// Insert 'NewString' (I.e. replace)
Tmp = Tmp + NewString.GetValue();
// Append everything after 'OldString'
Tmp = Tmp + m_Content.Substring(Pos + OldString.Length());
// Save
m_Content = Tmp;
// Find the next position
tPos = SubStr(Pos + NewString.Length()).Find(OldString);
Pos = Pos + NewString.Length() + tPos;
// Count how many replaces we made
Count++;
// If we only should replace the first occurence of 'OldString'
if (!ReplaceAll)
// Stop (-1 indicates that we didn't find 'OldString' again)
Pos = -1;
}
// Return the Count
return Count;
}
示例15: Printf
// Set the value of the string using "format" (as printf or string::format)
public ktString Printf(ktString Format, params object[] ParamList)
{
m_Content = string.Format(Format.GetValue(), ParamList);
return this;
}