سلام
من تو سی شارپ میخوام برنامه ای بنویسم که ادرس یه عکس رو بهش بدی و اون فقط نام و پسوند فایل رو نشون بده ولی دو خطا میده نمیدونم چرا همه چیز باید درست باشه!
Newline in constant
expected (
لطفا راهنمایی کنید حیاتیه! :52:
سلام
من تو سی شارپ میخوام برنامه ای بنویسم که ادرس یه عکس رو بهش بدی و اون فقط نام و پسوند فایل رو نشون بده ولی دو خطا میده نمیدونم چرا همه چیز باید درست باشه!
Newline in constant
expected (
لطفا راهنمایی کنید حیاتیه! :52:
احتمالا بخاطر اینه که از بک اسلش استفاده کردید
سورس رو بذارید تا بتونم بهتر راهنمایی کنم
?
private void button1_Click(object sender, EventArgs e)
{
string now="0";
for (int c=textBox1.TextLength;c>=0; c--)
{
textBox1.SelectionStart = c;
textBox1.SelectionLength = 1;
if (textBox1.SelectedText == "\")
{
textBox1.SelectionStart = c+1;
textBox1.SelectionLength = textBox1.TextLength;
now = textBox1.SelectedText;
break;
}
}
MessageBox.Show(now);
}
تو این مواقع باید قبل از string یه علامت @ بذارید این باعث میشه تا سی شارپ همه عبارت های خاص رو هم یک رشته بدونه
private void button1_Click(object sender, EventArgs e)
{
string now="0";
for (int c=textBox1.TextLength;c>=0; c--)
{
textBox1.SelectionStart = c;
textBox1.SelectionLength = 1;
if (textBox1.SelectedText == @"\")
{
textBox1.SelectionStart = c+1;
textBox1.SelectionLength = textBox1.TextLength;
now = textBox1.SelectedText;
break;
}
}
MessageBox.Show(now);
}
در اینجا میتونید به این صورت هم استفاده کنید
private void button1_Click(object sender, EventArgs e)
{
string now="0";
for (int c=textBox1.TextLength;c>=0; c--)
{
textBox1.SelectionStart = c;
textBox1.SelectionLength = 1;
if (textBox1.SelectedText == "\\")
{
textBox1.SelectionStart = c+1;
textBox1.SelectionLength = textBox1.TextLength;
now = textBox1.SelectedText;
break;
}
}
MessageBox.Show(now);
}
موفق باشید :smilingsmiley:
ندونستن عیب نیست، نپرسیدن چرا!