I just want to edit a txt and save the edited version.
In this case i replaced all the i's with q's.
Is there an easier way to do this? Without all the casting? -
static void Main(string[] args){
-
-
string[] text = File.ReadAllLines("test.txt");
-
char[] help;
-
-
for (int i = 0; i < text.Length; i++) {
-
-
help = text[i].ToArray();
-
-
for (int j = 0; j < help.Length; j++){
-
-
if (help[j] == 'i')
-
help[j] = 'q';
-
}
-
-
text[i] = new String(help);
-
-
}
-
File.WriteAllLines("test_alt.txt",text);
-
}
-
}
1 1325 - List<string> text = new List<string>();
-
string filelocation = null;
-
if (openFileDialog1.ShowDialog() == DialogResult.OK)
-
{
-
filelocation = openFileDialog1.FileName.ToString();
-
}
-
foreach (string line in File.ReadLines(filelocation))
-
{
-
string addthis;
-
if (line.Contains("i"))
-
{
-
addthis = line.Replace("i", "j");
-
}
-
else
-
{
-
addthis = line;
-
}
-
text.Add(addthis);
-
}
-
File.WriteAllLines(filelocation, text);
there is this method, you throw it once into a string, replace all i's to j's and then write the list back, there is a fiddly bit in the middle where line isnt added but addthis is, beause i couldnt set it as line = line.replace("i ","j"); or the compiler throws a wobbly because line is used for the rest of the loop, so i made the new string addthis that is always added, if the string contains an i they are turned to j's, assigned to addthis, and add this gets added, otherwise addthis is just directly equal to line, im sure there is a neater way of doing this but you asked for me to get rid of the castings so this was a quick throw together.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Johnny Meredith |
last post by:
I have seven huge fixed width text file that I need to import to Access.
They contain headers, subtotals, etc. that are not needed. There is also
some corrupt data that we know about and can correct once the data is in
Access (or during the import process itself). Furthermore, the text files
are poorly set up, such that some records may be "shifted" over a few
characters, and therefore the fixed width nature of the file is corrupted.
...
|
by: ALF |
last post by:
What's easiest way to replace a particular text string in
a text file by another and save the modified file?
Currently I know how to open a file, read the text
string, place it in a variable, and modify the string.
What I'd like to know is how to save the modified string
in the same file.
The alternative that's I'm trying to avoid is to create a
temporary auxiliary file in the process.
|
by: Matt |
last post by:
I want to delete the first line of a text file but it seems like a waste to
read in the entire file into memory, remove the line, and then write it out
again. Is there a way in VB.NET to delete the first line without reading in
the entire file and recreating it?
|
by: ritesh |
last post by:
Hi,
I'm facing a problem in which I need to edit an already created file,
and the editing needs to be done at the start of the file rather then
appending to the file.
OS - Linux,Solaris
For e.g.
I have a file test.txt created and I have the path to this file in a
|
by: DH |
last post by:
Hi,
I'm trying to strip the html and other useless junk from a html page..
Id like to create something like an automated text editor, where it
takes the keywords from a txt file and removes them from the html page
(replace the words in the html page with blank space) I'm new to python
and could use a little push in the right direction, any ideas on how to
implement this?
Thanks!
| |
by: list |
last post by:
Hi folks,
I am new to Googlegroups. I asked my questions at other forums, since
now.
I have an important question: I have to check files if they are
binary(.bmp, .avi, .jpg) or text(.txt, .cpp, .h, .php, .html). How to
check a file an find out if the file is binary or text?
Thanks for your help.
|
by: ray96 |
last post by:
i want the list of functions to edit a text file in c++ plz?
can i have 2 diffrent pointer to a file at time ?
how can i delete the last line of my text file?
|
by: Ikolder |
last post by:
Hello,
I hope someone can help me with this!
I have a problem editing a text file my file looks like this
11
13
15
16
23
|
by: ganesanji |
last post by:
hi to all,
I am new to php. I have to edit a text file using php. I saw the file system concepts modes. My problem is I want to change a particular text or word in a text file. How to find the index of the specific word. Is there any functions or methods available for change a particular word or finding index of a word...
For the example, consider a text file named ganesh.txt which content is shown below....
ganesh
is
working ...
|
by: bluemountain |
last post by:
Hi there,
Iam new to python forms and programming too
I had a text file where i need to extract few words of data from the header(which is of 3 lines) and search for the keyword TEXT1, TEXT2, TEXT3in entire file(file consisting of 150 lines) that is related to a particular id and get the sum of the, WRITES of TEXT1, TEXT2, TEXT3
ex: input file will be as below
Windows 2000 text text text text text text text
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |