TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Krpi1141 Krpi1141
NA
7
537
How to delete text between two texts in listbox
Sep 8 2019 8:46 AM
Hi For my application, I need a code that searches for Listbox text that has the beginning and end characters
code for open text to listbox
Stream myStream =
null
;
OpenFileDialog openFileDialog1 =
new
OpenFileDialog();
openFileDialog1.InitialDirectory =
"c:\\"
;
openFileDialog1.Filter =
"txt files (*.php)|*.php|All files (*.*)|*.*"
;
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory =
true
;
if
(openFileDialog1.ShowDialog() == DialogResult.OK) {
try
{
if
((myStream = openFileDialog1.OpenFile()) !=
null
) {
using
(myStream) {
textBox1.Text = File.ReadAllText(openFileDialog1.FileName);
}
}
}
catch
(Exception ex) {
MessageBox.Show(
"Error: Could not read file from disk. Original error: "
+ ex.Message);
}
}
// button 2
for
(
int
n = listBox1.Items.Count - 1; n >= 0; --n) {
string
s = listBox1.Items[n].ToString(); {
int
start = n.IndexOf(
"<-"
);
int
end = n.IndexOf(
"->"
); {
listBox1.Items.Remove(s);
Listbox will have text
for example
text text text
<-- text to be deleted
text to be deleted
text to be deleted ->
text text text
the program will delete everything written in <- -> and so it will stay
text text text
text text text
thank you
Reply
Answers (
3
)
string is imutable
implicitly and explicity