Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
how can i get the numbers that are coded in a ascii art with sticks?
the numberss are in a txt file und it contains this:
I must convert this txt file in
3 2 1 4 5
1 4 5
I read the text file so:
using (StreamReader sr = new StreamReader("SourceFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
sb.AppendLine(line);
}
}
string allines = sb.ToString();
Now, like the answer of #Zotta i have to save in two different strings (the first 4 lines and the seconds, than
then will be easier
Your numbers are 4 lines tall each => Split input into blocks of 4 Lines each
Your numbers are separated by columns of whitespace => Search for colums containing only whitespaces and split.
After you separated all the numbers, use a lookup table.
I don't know why this question is down-voted so much but I think it's interesting question. I'll answer giving a general approach other than hardcoding the possible results by finding the characters and that would work with different "ASCII font".
If you're looking for a library, maybe you can look at captcha decoding on google. There is a comprehensive article here if you want to do it yourself for ASCII specifically:
http://www.boyter.org/decoding-captchas/
Also, since most libraries probably only support images, maybe you'll need to convert your ascii art text file into a bitmap by rendering it yourself.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a text file containing numbers both negative and positive and want them to display the total in a TextBox. The text file is arranged as follows
0
25
25
-10
67.5
33.33
-45
and so on. There can be different numbers on each line both positive and negative and to 2 decimal place at the most. I'm sure its quite simple but I don't know how to do it. Can anybody help?
var total = Directory.EnumerateFiles ("C:\\", "*.txt")
.Select (filePath => File.ReadLines (filePath)
.Select (x => decimal.Parse (x))
.Sum ())
.Sum ();
Of course this code needs some improvements (error handling, parsing etc.).
Assume you have text files with contents 1,3,33,-44.3 in each files on D drive. You can try this
decimal total = 0;
foreach (string file in Directory.EnumerateFiles("D:/", "*.txt"))
{
string content = File.ReadAllText(file);
total += Convert.ToDecimal(content);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Hello experts, I have to generate series of folders from a TextBox into specified location.I am having two textboxes to specify the limit of folders(say 30 folders).The problem am facing is that the folder names that i will be providing are alpha-numeric(say 121cs3h101) .
How to set limit when i provide an alpha-numeric values?
(For example: i provide textbox1=12cs3h101 and textbox2=12cs3h131 , i need the series limit to be generated). I am working with visual studio 2013 in c# windows form application. Thanks in advance.
ok I will try to give you a lead.
To parse a string or find specific characters one can use RegEx.Match or a simler method called String.Split. In both cases you have to be aware how your string is structured and how it can vary. The limits of variation are very important.
If as you say the beginning is always"12cs3h" you can either split the string at the character 'h'.
string[] sa = s.Split('h');
Or you can even use the index of 'h' (since the length seems to be fixed) and take the rest of the string to get the numbers.
int index = s.IndexOf('h');
The rest is up to you, ... convert, enumerate and so on.
EDIT: There is a nice method that does the enumeration job for you: Enumerable.Range Good luck
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a C# task to do and I am stuck on part of the coding. I am using StreamReader to read a .txt file which contains group exam grade data (e.g. ADCBCBBBADEBCCBADBAACDCCBEDCBACCFEABBCBBBCCEAABCBB), I need the code to work out how many A's, B's etc there are inside each set of data, I thought about using some form of count++ code but each attempt just throws errors.
I want it to print onto console the number of A's in that line of the .txt file.
I hope that makes sense, I understand how to do the rest but I just needed a hand on this section.
Consider using System.Linq, eg...
string myString = "ADCBCBBBADEBCCBADBAACDCCBEDCBACCFEABBCBBBCCEAABCBB";
int countOfAs = myString.Count(x => x == 'A');
//Result: 9
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
What I've got is a text file with some (hypothetical) students and their attendance.
Looks like this:
Stud1
LOOOALLOOAAL
Stud2
OOOOOOOAOOOO
Stud3
LLLLOOOOALLA
So what I want to do, is assign say Stud1 to show Stud1: LOOOALLOOAAL etc etc.
Any ideas?
actually your post is kind of "unclear" to readers but I did get your point regarding reading lines from text to variables
I suggest you use File.ReadAllLines, then format your text with each values separated per line
so it goes like this
Source.txt
LOOOALLOOAAL
OOOOOOOAOOOO
LLLLOOOOALLA
then your line of code will be
string[] students = File.ReadAllLines("Source.txt");
thus the values would be
students[0] = LOOOALLOOAAL
students[1] = OOOOOOOAOOOO
students[2] = LLLLOOOOALLA
the code File.ReadAllLines() gets every line of text from your source file until it reaches the endline and stores it into an array of string. if you needed your values for calculations, then you'll need to parse such values
I just showed you how to get values from text to variables. how you show them as output will be on you.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have a FASTA file containing several protein sequences. The format is like
----------------------
>protein1
MYRALRLLARSRPLVRAPAAALASAPGLGGAAVPSFWPPNAAR
MASQNSFRIEYDTFGELKVPNDKYYGAQTVRSTMNFKIGGVTE
RMPTPVIKAFGILKRAAAEVNQDYGLDPKIANAIMKAADEVAE
GKLNDHFPLVVWQTGSGTQTNMNVNEVISNRAIEMLGGELGSK
IPVHPNDHVNKSQ
>protein2
MRSRPAGPALLLLLLFLGAAESVRRAQPPRRYTPDWPSLDSRP
LPAWFDEAKFGVFIHWGVFSVPAWGSEWFWWHWQGEGRPYQRF
MRDNYPPGFSYADFGPQFTARFFHPEEWADLFQAAGAKYVVLT
TKHHEGFTNW*
>protein3
MKTLLLLAVIMIFGLLQAHGNLVNFHRMIKLTTGKEAALSYGF
CHCGVGGRGSPKDATDRCCVTHDCCYKRLEKRGCGTKFLSYKF
SNSGSRITCAKQDSCRSQLCECDKAAATCFARNKTTY`
-----------------------------------
Is there a good way to read in this file and store the sequences separately?
Thanks
To do this one way is to:
Create a vector where each location
holds a name and the sequence
Go through the file line by line
If the line starts with > then add
an element to the end of the vector
and save the line.substring(1) to
the element as the protein name.
Initialize the sequence in the
element to equal "".
If the line.length == 0 then it is
blank and do nothing
Else the line doesn't start with >
then it is part of the sequence so
go current vector element.sequence
+= line. Thus way each line between >protein2 and >protein3 is
concatenated and saved to the
sequence of protein2
I think maybe a little more detail about the exact file structure could be helpful. Just looking at what you have (and a quick peek at the samples on wikipedia) suggest that the name of the protein is prepended with a >, followed by at least one line break, so that would be a good place to start.
You could split the file on newline, and look for a > character to determine the name.
From there it is a little less clear because I'm not sure if the sequence data is all in one line (no linebreaks) or if it could have linebreaks. If there are none, then you should be able to just store that sequence information, and move on to the next protein name. Something like this:
var reader = new StreamReader("C:\myfile.fasta");
while(true)
{
var line = reader.ReadLine();
if(string.IsNullOrEmpty(line))
break;
if(line.StartsWith(">"))
StoreProteinName(line);
else
StoreSequence(line);
}
If it were me, I would probably use TDD and some sample data to build out a simple parser, and then keep plugging in samples until I felt I had covered all of major variances in the format.
Can you use a language other than C#? There are excellent libraries for dealing with FASTA files and other biological sequence in Perl, Python, Ruby, Java, and R (off the top of my head). They're usually branded Bio* (i.e. BioPerl, BioJava, etc)
If you're interested in C or C++, check out the answers to this question over at Biostar:
http://biostar.stackexchange.com/questions/1516/c-c-libraries-for-bioinformatics
Do yourself a favor, and don't reinvent the wheel if you don't have to.