本文整理汇总了C#中System.String.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# String.GetLength方法的具体用法?C# String.GetLength怎么用?C# String.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AlignString
public static String[,] AlignString(String[,] Data, String[] Filler,int[] columnSpace , Font Font)
{
int NRow = Data.GetLength(0);
int NCol = Data.GetLength(1);
String[,] result = new String[NRow, NCol];
System.Windows.Forms.Button aButton = new System.Windows.Forms.Button();
Graphics G = aButton.CreateGraphics();
System.Drawing.StringFormat sf = System.Drawing.StringFormat.GenericTypographic;
sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
for (int j = 0; j < NCol; j++)
{
//計算此欄字串的最大長度
SizeF maxSize = G.MeasureString(Data[0, j], Font, 0, sf);
for (int i = 1; i < NRow; i++)
{
SizeF sizeF = G.MeasureString(Data[i, j], Font, 0, sf);
if (sizeF.Width > maxSize.Width)
maxSize = sizeF;
}
SizeF fillerSizeF = G.MeasureString(Filler[j], Font, 0, sf);
SizeF ColSize = new SizeF(maxSize.Width + fillerSizeF.Width * columnSpace[j], maxSize.Height);
for (int i = 0; i < NRow; i++)
{
result[i, j] = Data[i, j];
while (G.MeasureString(result[i, j], Font, 0, sf).Width < ColSize.Width)
result[i, j] += Filler[j];
}
}
return result;
}
示例2: CreateGrid
/// <summary>
/// Kreiranje "tablice" ocjena na temelju proslijeđene string matrice.
/// </summary>
/// <param name="matrix"></param>
public void CreateGrid(String[,] matrix)
{
contentGrid.ColumnDefinitions.Clear();
contentGrid.RowDefinitions.Clear();
contentGrid.Children.Clear();
int height = 50;
while (height * (matrix.GetLength(0) + 1) > contentGrid.Height)
height--;
for (int i = 0; i < matrix.GetLength(0); i++) {
RowDefinition rowDef = new RowDefinition();
rowDef.Height = new GridLength(height);
contentGrid.RowDefinitions.Add(rowDef);
for (int j = 0; j < matrix.GetLength(1); j++) {
ColumnDefinition columnDef = new ColumnDefinition();
columnDef.Width = new GridLength(j == 0 ? 150 : (contentGrid.Width / (matrix.GetLength(1) + 2)));
contentGrid.ColumnDefinitions.Add(columnDef);
Label label = new Label();
if (i == 0 || j == 0)
label.FontWeight = FontWeights.Bold;
Grid.SetRow(label, i);
Grid.SetColumn(label, j);
label.Content = matrix[i, j];
contentGrid.Children.Add(label);
}//for 2
}
}
示例3: write
/// <summary>
/// Schreibt die Daten in "data" in die Datei "file"
/// </summary>
/// <example>
/// <code>
///
/// String[,] data = new String[2, 2];
/// for (int i = 0; i < data.GetLength(0); i++)
/// for (int j = 0; j < data.GetLength(1); j++)
/// data[i, j] = i + "_" + j;
/// CSV.write(data, "test.csv");
///
/// </code>
/// Schreibt folgende Matrix in die Datei "test.csv"
///
/// 0_0 0_1
/// 1_0 1_1
/// </example>
public static void write(String[,] data, String file)
{
StreamWriter sw = new StreamWriter(@file);
for (int i = 0; i < data.GetLength(0); i++) {
for (int j = 0; j < data.GetLength(1); j++) {
sw.Write(data[i, j] + ";");
}
sw.Write("\n");
}
sw.Close();
}
示例4: DisplayBoard
public static void DisplayBoard(String[,] gameBoard)
{
for (int i = 0; i < gameBoard.GetLength(0); i++)
{
for (int j = 0; j < gameBoard.GetLength(1); j++)
{
Console.Write(" " + gameBoard[i, j] + " ");
}
Console.WriteLine("");
}
}
示例5: GetRGBMapFromPixelMap
/// <summary>
/// Erzeugt eine RGBMap(string[x,y]="255,255,255") aus einer PixelMap(byte[x,y,rgba]=0-255).
/// </summary>
public static string[,] GetRGBMapFromPixelMap(byte[, ,] pPixelMap)
{
string[,] TmpRGBMap = new String[pPixelMap.GetLength(0),pPixelMap.GetLength(1)];
for (int i = 0; i < TmpRGBMap.GetLength(0); i++)
{
for (int t = 0; t < TmpRGBMap.GetLength(1); t++)
{
TmpRGBMap[i,t] = pPixelMap[i, t, 0].ToString() + "," + pPixelMap[i, t, 1].ToString() + "," + pPixelMap[i, t, 2].ToString();
}
}
return TmpRGBMap;
}
示例6: TestIntialBoardElems
public void TestIntialBoardElems()
{
Game game = new Game();
String[,] gameBoard = new String[4,4];
for (int i = 0; i < gameBoard.GetLength(0); i++)
{
for (int j = 0; j < gameBoard.GetLength(1); j++)
{
Debug.Write(" " + gameBoard[i, j] + " ");
}
Debug.WriteLine("");
}
}
示例7: readCSV
//reads a CSV into a String[,]
public static String[,] readCSV(string s)
{
String[] lines = File.ReadAllLines(s);
String[,] vals = new String[lines.Length, lines[0].Split(',').Length];
for (int i = 0; i < vals.GetLength(0); i++)
{
String[] thisLine = lines[i].Split(',');
for (int j = 0; j < vals.GetLength(1); j++)
{
vals[i, j] = thisLine[j];
}
}
return vals;
}
示例8: getRange
public String[,] getRange(int startrow, int startcol, int endrow, int endcol)
{
String[,] data = new String[endrow - startrow + 1, endcol - startcol + 1];
for (int i = 0; i < data.GetLength(0); i++)
{
for (int j = 0; j < data.GetLength(1); j++)
{
data[i, j] = (((Range)xlWorksheet.Cells[i + startrow, j + startcol]).Value2 != null
? ((Range)xlWorksheet.Cells[i + startrow, j + startcol]).Value2.ToString()
: "");
}
}
return data;
}
示例9: createMapItemList
public MapItem[,] createMapItemList(String[,] map)
{
int size = map.GetLength(0);
MapItem[,] itList = new MapItem[size, size];
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
itList[j, i] = new MapItem();
/*if (new String[] { MapItem.BLANK, MapItem.COIN, MapItem.LIFEPACK }.Contains(map[j, i], StringComparer.Ordinal))
itList[j, i].Contain = MapItem.BLANK;
else
itList[j, i].Contain = MapItem.STONE;*/
itList[j, i].Contain = map[j, i];
if (DecodeOperations.playerDir.Contains(map[j, i],StringComparer.Ordinal))
{
itList[j, i].Dir = Array.FindIndex(DecodeOperations.playerDir, pl => pl.Contains(map[j, i]));
}
itList[j, i].Name = i.ToString() + "," + j.ToString();
itList[j, i].Pre = null;
itList[j, i].Dis = Int32.MaxValue - 1;
}
}
return itList;
}
示例10: BorrowBook_Load
private void BorrowBook_Load(object sender, EventArgs e)
{
bookDetail.Rows.Clear();
string[,] book = new String[DBCommand.countRow(), 10];
try
{
book = DBCommand.searchBook("", "", "", "", "", "", "");
for (int i = 0; i < book.GetLength(0); i++)
{
bookDetail.Rows.Add();
for (int j = 0; j < 10; j++)
{
bookDetail.Rows[i].Cells[j].Value = book[i, j];
}
}
}
catch (FileLoadException e2)
{
Console.WriteLine(e2);
bookDetail.Rows.Add();
for (int j = 0; j < 10; j++)
{
bookDetail.Rows[0].Cells[j].Value = "N/A";
}
}
}
示例11: searchBtn_Click
private void searchBtn_Click(object sender, EventArgs e)
{
bookDetail.Rows.Clear();
String[,] book = new String[DBCommand.countRow(), 10];
try
{
book = DBCommand.searchBook(nameField.Text, "", writerField.Text, "", "", publishedYrBox.Text, "");
for (int i = 0; i < book.GetLength(0); i++)
{
bookDetail.Rows.Add();
for (int j = 0; j < 10; j++)
{
bookDetail.Rows[i].Cells[j].Value = book[i, j];
}
}
}
catch (FileLoadException e2)
{
Console.WriteLine(e2);
bookDetail.Rows.Add();
for (int j = 0; j < 10; j++)
{
bookDetail.Rows[0].Cells[j].Value = "N/A";
}
}
}
示例12: TestMergeDown
public void TestMergeDown()
{
Game game = new Game();
String[,] gameBoard = new String[4, 4] { { "0", "0", "0", "0" },
{ "0", "2", "4", "4" },
{ "0", "4", "2", "2" },
{ "0", "8", "4", "8" }};
gameBoard = game.MoveDown(gameBoard);
for (int i = 0; i < gameBoard.GetLength(0); i++)
{
for (int j = 0; j < gameBoard.GetLength(1); j++)
{
Debug.Write(" " + gameBoard[i, j] + " ");
}
Debug.WriteLine("");
}
}
示例13: Main
public static void Main(String[] args)
{
if (args.GetLength(0) < 1)
{
usage();
return;
}
int argi = 0;
bool quiet = false;
if (args[argi] == "-q")
{
quiet = true;
argi++;
}
if (argi == args.GetLength(0))
{
usage();
return;
}
String url = args[argi];
if (!quiet)
Console.WriteLine("Loading Schema: " + url);
if (argi < (args.GetLength(0) - 1))
{
if (!quiet)
Console.WriteLine("Outputing to file: " + args[argi + 1]);
StreamWriter output =
new StreamWriter(new FileStream(args[argi + 1], FileMode.Create));
NormalizeXmlSchema(url, output);
}
else
{
NormalizeXmlSchema(url, Console.Out);
}
}
示例14: Execute
public static int Execute(String[] args)
{
HttpServer httpServer;
if (args.GetLength(0) > 0)
{
httpServer = new MyHttpServer(IPAddress.Any, Convert.ToInt16(args[0]));
}
else
{
httpServer = new MyHttpServer(IPAddress.Any, 8080);
}
Thread thread = new Thread(new ThreadStart(httpServer.Listen));
thread.Start();
return 0;
}
示例15: Main
public static int Main(String[] args)
{
HttpServer httpServer;
if (args.GetLength(0) > 0)
{
httpServer = new MyHttpServer(Convert.ToInt16(args[0]));
}
else
{
httpServer = new MyHttpServer(8080);
}
Thread thread = new Thread(new ThreadStart(httpServer.listen));
thread.Start();
return 0;
}