本文整理汇总了C#中System.String.substring方法的典型用法代码示例。如果您正苦于以下问题:C# String.substring方法的具体用法?C# String.substring怎么用?C# String.substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.substring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CBC
private String CBC(String key, String text)
{
//mode enkripsi CBC
//asumsi
//1. panjang key = 8
//2. panjang text merupakan kelipatan 8
int a,b,c;
int size;
String temp = String.Empty;
String keyGen = "00000000";
String tempKey = String.Empty;
String result = String.Empty;
a=0; //count jumlah char
b=0; //count jumlah penggunaan key
while(a<text.Length){
temp = text.substring(a,8);
//melakukan XOR P dan C
tempKey = varXOR(temp,keyGen);
//harusnya ada fungsi XOR, tapi baru asumsi, fungsi masih salah
result += varXOR(tempKey,keyGen);
a+=8;
b++;
}
return result;
}
示例2: EBC
//========================================================================
//========================================================================
private String EBC(String key, String text)
{
//mode enkripsi EBC
//asumsi
//1. panjang key = 8
//2. panjang text merupakan kelipatan 8
int a,b,c;
int size;
String temp = String.Empty;
String keyGen = String.Empty;
String result = String.Empty;
a=0; //count jumlah char
b=0; //count jumlah penggunaan key
while(a<text.Length){
temp = text.substring(a,8);
//generate fungsi key
//key akan di-generate berdasarkan jumlah penggunaan kunci,
//key juga akan di-reversi jika telah melakukan 5 penggunaan
keyGen = generatorKey(key,b);
//harusnya ada fungsi XOR, tapi baru asumsi, fungsi masih salah
result += varXOR(temp,keyGen);
a+=8;
b++;
}
return result;
}
示例3: parseVerboseInt
private int parseVerboseInt(String input) {
String loadedString = String.format("%s", input);
boolean negative = false;
int base = 10;
int shift = 3;
int retVal = -1;
if (input.charAt(0) == '-') {
negative = true;
input = input.substring(1);
}
if (input.indexOf("0x") == 0) {
base = 16;
input = input.substring(2);
}
if (input.indexOf("b") == input.length() - 1) {
shift = 0;
input = input.substring(0, input.length() - 1);
}
try {
retVal = Integer.parseInt(input, base);
} catch (Exception e) {
addGeneralError(loadedString);
validComponent = false;
}
if (validComponent) {
retVal <<= shift;
if (negative)
retVal = 0 - retVal;
}
return retVal;
}
示例4: getRelativePath
static public String getRelativePath(String path1, String path2)
{
if (!path1.startsWith(path2))
return path1;
return path1.substring(path2.length());
}
示例5: CAttrValue
public CAttrValue(String strAttrib, String strValue)
{
m_strAttrib = strAttrib;
m_strValue = strValue;
if ( m_strAttrib.endsWith("-rhoblob") )
{
m_strBlobSuffix = "-rhoblob";
m_strAttrib = m_strAttrib.substring(0,m_strAttrib.length()-m_strBlobSuffix.length());
}
}
示例6: changeBaseName
public static String changeBaseName( String path, String szFileName )
{
int basePos = findLastSlash(path);
if (basePos >= 0 && basePos < path.length() - 1)
{
String res = path.substring(0, basePos + 1);
res += szFileName;
return res;
}
return join(path, szFileName);
}
示例7: makeStringSize
private String makeStringSize(String str, int nSize)
{
if ( str.length() >= nSize )
return str.substring(0, nSize);
else {
String res = "";
for( int i = 0; i < nSize - str.length(); i++ )
res += ' ';
res += str;
return res;
}
}
示例8: generateCombosHelper
public static void generateCombosHelper(List<String> combos,
String prefix, String remaining)
{
// The current digit we are working with
int digit = int.Parse(remaining.Substring(0, 1));
if (remaining.Length == 1) {
// We have reached the last digit in the phone number, so add
// all possible prefix-digit combinations to the list
for (int i = 0; i < mappings[digit].length; i++) {
combos.add(prefix + mappings[digit][i]);
}
} else {
// Recursively call this method with each possible new
// prefix and the remaining part of the phone number.
for (int i = 0; i < mappings[digit].length; i++) {
generateCombosHelper(combos, prefix + mappings[digit][i],
remaining.substring(1));
}
}
}
示例9: canonicalizePath
/**
* Canonicalize the path, i.e. remove ".." and "." occurences.
*
* @param path the path to be canonicalized
* @return the canonicalized path
*/
public static String canonicalizePath(String path)
{
int dirIndex;
while ((dirIndex = path.indexOf("/./")) >= 0)
{ //$NON-NLS-1$
path = path.substring(0, dirIndex + 1)
+ path.substring(dirIndex + 3);
}
if (path.endsWith("/."))
{ //$NON-NLS-1$
path = path.substring(0, path.length() - 1);
}
while ((dirIndex = path.indexOf("/../")) >= 0)
{ //$NON-NLS-1$
if (dirIndex != 0)
{
path = path.substring(0, path
.lastIndexOf('/', dirIndex - 1))
+ path.substring(dirIndex + 3);
}
else
{
path = path.substring(dirIndex + 3);
}
}
if (path.endsWith("/..") && path.length() > 3)
{ //$NON-NLS-1$
path = path.substring(0, path.lastIndexOf('/',
path.length() - 4) + 1);
}
return path;
}
示例10: decode
/**
* Decodes the string argument which is assumed to be encoded in the {@code
* x-www-form-urlencoded} MIME content type using the UTF-8 encoding scheme.
* <p>
*'%' and two following hex digit characters are converted to the
* equivalent byte value. All other characters are passed through
* unmodified.
* <p>
* e.g. "A%20B%20C %24%25" -> "A B C $%"
* <p>
* Called from URI.getXYZ() methods
*
* @param s
* java.lang.String The encoded string.
* @return java.lang.String The decoded version.
*/
static String decode(String s)
{
//throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
java.io.ByteArrayOutputStream outJ = new java.io.ByteArrayOutputStream();
for (int i = 0; i < s.length();) {
char c = s.charAt(i);
if (c == '%') {
outJ.reset();
do {
if (i + 2 >= s.length()) {
throw new java.lang.IllegalArgumentException("Incomplete % sequence at: "+ i); //$NON-NLS-1$
}
int d1 = java.lang.Character.digit(s.charAt(i + 1), 16);
int d2 = java.lang.Character.digit(s.charAt(i + 2), 16);
if (d1 == -1 || d2 == -1) {
throw new java.lang.IllegalArgumentException("Invalid % sequence ("+s.substring(i, i + 3)+") at: "+java.lang.StringJ.valueOf(i));
}
outJ.write((byte) ((d1 << 4) + d2));
i += 3;
} while (i < s.length() && s.charAt(i) == '%');
result.append(outJ.toString(encoding));
continue;
}
result.append(c);
i++;
}
return result.toString();
}
示例11: GetTypeName
/// <summary>
/// This is used to acquire the name of the method in a Java Bean
/// property style. Thus any "get", "is", or "set" prefix is
/// removed from the name and the following character is changed
/// to lower case if it does not represent an acronym.
/// </summary>
/// <param name="name">
/// this is the name of the method to be converted
/// </param>
/// <param name="type">
/// this is the type of method the name represents
/// </param>
/// <returns>
/// this returns the Java Bean name for the method
/// </returns>
public String GetTypeName(String name, MethodType type) {
int prefix = type.getPrefix();
int size = name.length();
if(size > prefix) {
name = name.substring(prefix, size);
}
return Reflector.GetName(name);
}
示例12: addObjectNotify
public void addObjectNotify(String strSrcName, String strObject )
{
lock(m_mxObjectNotify)
{
m_strSingleObjectSrcName = strSrcName;
m_strSingleObjectID = strObject.charAt(0) == '{' ? strObject.substring(1,strObject.length()-2) : strObject ;
}
}
示例13: parse
/// <summary>
/// Parse String with given pattern on ParsePosition to Data object
/// </summary>
/// <param name="s"></param>
/// <param name="pos"></param>
/// <returns></returns>
public java.util.Date parse(String s, ParsePosition pos)
{
DateTime date = DateTime.ParseExact(s.substring(pos.getIndex()), pattern, CultureInfo.InvariantCulture);
return new java.util.Date(date.getTime());
}
示例14: node
public override Preferences node(String name)
{
AbstractPreferences startNode = null;
lock (lockJ) {
checkState();
validateName(name);
if ("".equals(name)) { //$NON-NLS-1$
return this;
} else if ("/".equals(name)) { //$NON-NLS-1$
return root;
}
if (name.startsWith("/")) { //$NON-NLS-1$
startNode = root;
name = name.substring(1);
} else {
startNode = this;
}
}
try {
return startNode.nodeImpl(name, true);
} catch (BackingStoreException e) {
// should not happen
return null;
}
}
示例15: write
/**
* Writes {@code count} characters from {@code str} starting at {@code
* offset} to the target.
*
* @param str
* the non-null string containing the characters to write.
* @param offset
* the index of the first character in {@code str} to write.
* @param count
* the number of characters from {@code str} to write.
* @throws IndexOutOfBoundsException
* if {@code offset < 0} or {@code count < 0}, or if {@code
* offset + count} is greater than the length of {@code str}.
*/
public override void write(String str, int offset, int count)
{
write(str.substring(offset, offset + count).toCharArray());
}