-3
我正在使用MVC 3.問題是如果字符串的長度超過10,我想要中斷字符串。來自數據庫的字符串值是用戶名。我想申請一個圖像上該字符串.. 例當字符串長度超過10時出現換行符char
public Image (string Name)
{
}
因此如何打破名字符串,如果它是超過10字符?
public FileResult image(string image)
{
Bitmap bitMapImage = new Bitmap(Server.MapPath("/Content/themes/base/images/photo.png"));
// Bitmap bitMapImage = new Bitmap("/Content/themes/base/images/del02s(1).jpg");
//TODO : comment for revert the cation of no photo
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
int count = image.Length;
string[] arr4 = new string[count];
if (image.Length > 9)
{
string imges = image
}
graphicImage.DrawString(image, new Font("Trebuchet MS,Trebuchet,Arial,sans-serif", 10, FontStyle.Bold), SystemBrushes.WindowFrame, new Point(15, 5));
graphicImage.DrawArc(new Pen(Color.Red, 3), 90, 235, 150, 50, 0, 360);
MemoryStream str = new MemoryStream();
bitMapImage.Save(str, ImageFormat.Png);
return File(str.ToArray(), "image/png");
}
檢查了這一點
靜態無效的主要(字串[] args){
string image = "1234567890abcdefghijklmnopqrsy";
int count = image.Length;
if (image.Length > 9)
{
//getting Error
string img1 = image.Substring(0, 10);
string img2 = image.Substring(10, count);//getting Error Index and length //must refer to a location within the string.
//Parameter name: length"
string imge3 = img1 + "\n";
string img4 = imge3 + img2;
Console.WriteLine(img4);
}
}
如果你要發佈那麼請花點時間讓它可讀。不要在標題中加入不必要的標籤,並注意拼寫。 – slugster
我已經這樣做了 – Agha