连续向字符串添加数字
Continuously add digits to a string
只是一个快速的,我想不断地向字符串添加数字。我做的第一件事是删除字符串的最后一个字符,现在应该连续添加从 1 开始的数字。片段如下:
using System;
using System.Collections.Generic;
namespace ConsoleApplication3
{
class Class1
{
public static String source = "#box1";
static string dest;
public static void Main(String[] args)
{
try
{
if (source.Length > 0)
{
dest = source.Substring(0, source.Trim().Length - 1);
}
Console.WriteLine(dest);
Console.ReadLine();
}
catch(Exception e){ e.ToString(); }
}
}
}
输出应如下所示:
#box1
#box2
#box3
#box4
#box5
等等……
如果您有最大值:
for (int i = 1; i <= max; i++)
{
Console.WriteLine("#Box" + i);
}
没有最大值,但这不是一个好主意:
count = 1
while (1 > 0)
{
Console.WriteLine("#Box" + count);
count++;
}
你也可以在 for 循环中做 no max,但我只是想在循环中给你更多的选择。
谢谢大家,
我是这样解决的。抱歉,我必须 post 使用它的真实代码。实在是太忙了,没法再编辑伪代码了
public static String RegistrationFailedPanels = UserValidations.RegistrationFailedPanels;
public static String CloseFailedPanel = UserValidations.CloseFailedPanel;
static int count = 0;
public void LoginFailed(String InputConstant, String FailedLogin)
{
++count;
InputConstant = RegistrationFailedPanels.Substring(0, RegistrationFailedPanels.Trim().Length-1);
FailedLogin = CloseFailedPanel.Substring(0, CloseFailedPanel.Trim().Length-1);
new LoginValidations(driver).WaitForATime(InputConstant +count);
driver.FindElement(By.CssSelector(FailedLogin +count)).Click();
}
只是一个快速的,我想不断地向字符串添加数字。我做的第一件事是删除字符串的最后一个字符,现在应该连续添加从 1 开始的数字。片段如下:
using System;
using System.Collections.Generic;
namespace ConsoleApplication3
{
class Class1
{
public static String source = "#box1";
static string dest;
public static void Main(String[] args)
{
try
{
if (source.Length > 0)
{
dest = source.Substring(0, source.Trim().Length - 1);
}
Console.WriteLine(dest);
Console.ReadLine();
}
catch(Exception e){ e.ToString(); }
}
}
}
输出应如下所示:
#box1
#box2
#box3
#box4
#box5
等等……
如果您有最大值:
for (int i = 1; i <= max; i++)
{
Console.WriteLine("#Box" + i);
}
没有最大值,但这不是一个好主意:
count = 1
while (1 > 0)
{
Console.WriteLine("#Box" + count);
count++;
}
你也可以在 for 循环中做 no max,但我只是想在循环中给你更多的选择。
谢谢大家, 我是这样解决的。抱歉,我必须 post 使用它的真实代码。实在是太忙了,没法再编辑伪代码了
public static String RegistrationFailedPanels = UserValidations.RegistrationFailedPanels;
public static String CloseFailedPanel = UserValidations.CloseFailedPanel;
static int count = 0;
public void LoginFailed(String InputConstant, String FailedLogin)
{
++count;
InputConstant = RegistrationFailedPanels.Substring(0, RegistrationFailedPanels.Trim().Length-1);
FailedLogin = CloseFailedPanel.Substring(0, CloseFailedPanel.Trim().Length-1);
new LoginValidations(driver).WaitForATime(InputConstant +count);
driver.FindElement(By.CssSelector(FailedLogin +count)).Click();
}