I've searched online and on StackOverflow, but I can't seem to find the answer to my question, although some of them came very close.
I am programming for .Net in Delphi Prism. I have a RichTextBox on a WinForm and I need to insert a line of text at the top every time program does insert. So, I am doing the following and it runs upto the line and raises the following exception.
offending code:
RichTextBox1.Lines.SetValue(str,0);
Exception:
Index was outside the bounds of the array
I think, I think I know why it is raising the exception. It's because there are no lines inserted into RichTextBox. So, my program really can't insert any line of text. I need to really insert line of text at the top everytime my program inserts a new line of text.
If I do call RichTextBox1.AppendText(str);, then it works and inserts the str text without newline, but it appends at the end. I want it inserting text at the top every time.
How do you insert line of text into RichTextBox?
Thanks.
The Lines property of the textbox is simply an array of string. So you need to add one element, move all elements one index down and insert your new text at the first index.
Also the Text property of the textbox is a string. Strings in .NET are immutable, so you need to fully replace the value.
One approach would be like this:
RichTextBox1.Text := "YourNewText" + Environment.NewLine + RichTextBox1.Text;
Related
This is on Numbers on Mac: I generate a paragraph of text from a row where columns hold parts of text. However, as some cells are empty, I had to use conditional ISEMPTY for the formula to work:
""&B9&" "&IF(ISBLANK(C9);"";C9)&" "&IF(ISBLANK(D9);"";D9)&" "&IF(ISBLANK(E9);"";E9)&" "&IF(ISBLANK(F9);"";F9)&" "&G9&" "&H9&""
This does function, but I end up with double spaces in areas where I have one or more columns empty (so the spaces double).
Is there a way I could use an another conditional like ISEMPTY(ISEMPTY...) to get rid of those?
This is not a huge problem, but is annoying and time consuming, because I have to fix these texts afterwards (there is a lot of them). :-(
Change the parts with &" "& from IF(ISBLANK(C9);"";C9)&" "&into IF(ISBLANK(C9);"";C9&" ")&
In your formula you check if C9 is blank. Whether blank or not it's followed by a " " space. So if blank you get a space added, but no data prior to it. If the next is empty too, you get another space without data etc..
By including the &" " inside the if statement it will only add a space if C9 is not blank. Blank cell adds no data and no space.
=TRIM(CONCATENATE(B9;" ";C9;" ";D9;" ";E9;" ";F9;" ";G9;" ";H9))
Maybe you should learn about TEXTJOIN..
I got a CSV file from my front-end as a XString and after I convert it into String it looks as follows:
In the next step I'm trying to perform SPLIT lv_string AT '##' INTO TABLE itab so I can get my data but it doesn't split anything, itab contains one line equal to lv_string.
If I try REPLACE '#' IN lv_string WITH space, lv_string doesn't change and sy-subrc is 4.
From my point of view I have this problem because the symbol # is used by SAP in this context as a symbol for non-printable symbols (that result from the conversion byte->string).
My question is: how may I use SPLIT/REPLACE with # in this case?
I also thought that I can change the SAP code page when converting XString to String but I already use the SAP code page 4110 (utf-8) and don't know a better alternative...
When you display a variable with the debugger, it displays the generic character # (U+0023) for all control characters which are not assigned a glyph ("non-printable symbols" as you say).
If the variable corresponds to the contents of a text file, and ## frequently occurs, there is a big chance that it's the combination of the control characters U+000D and U+000A which correspond to "newline" in Windows files.
In the backend debugger, you can check the hexadecimal values of those characters by clicking the button "Hexadezimal" (shown in your screenshot).
You may use the variable CL_ABAP_CHAR_UTILITIES=>CR_LF which contains those two control characters.
I have a large CSV with a large number of columns. I am trying to count the number of lines using
File.open(file).readlines.to_a.compact.count.to_i
It displays 57 although there are only 56 rows. Upon close examination I found that a part of one line is wrapped to form the next line. How to get the correct count?
Upon close examination I found that a part of one line is wrapped to form the next line. How to get the correct count?
You need to show an example of the incoming data if you want us to help beyond generic answers.
To fix the problem, you have to be able to identify the line. We can't help you there because it could look like anything. Making a wild guess, I'd say that one of the columns had an embedded new-line in it, which forces the line to wrap.
It the file is a true CSV file, that column should be wrapped in double-quotes, so you could search the file for lines that do NOT end with whatever data type should be in the last column, then read the next line, join them, then rewrite the file. But, again, we have nothing to work with, because your file's format could be a huge number of different things.
Your best bet is to use the CSV class that comes with Ruby, and let it read the file, instead of trying to treat it like a text file. CSV files are text, but they are formatted to maintain the columns and rows, so using the CSV class will give you a better chance of getting at the data.
Looking at your code:
There are a number of ways to count the number of lines in a file, including the easiest which is:
`wc -l /path/to/file`.to_i
if you're using *nix.
Using File.open(file).readlines.to_a is horribly redundant and not fast or scalable if your file is big.
readlines returns an array.
to_a returns an array.
Why turn the array into an array?
readlines loads an entire file into memory, then splits it on line ends into an array. That process can be a lot slower than simply reading the file line-by-line and incrementing a counter, plus "slurping" can make your program crawl if the file is larger than available memory.
See "Why is "slurping" a file not a good practice?" for more information.
compact removes nils from an array. readlines should never return any nils so compact will iterate over the array looking for something that shouldn't exist.
count returns an integer.
to_i converts the receiver to an integer.
In other words, to_i is turning an integer into an integer. Why?
If you want to do it in Ruby instead of using wc -l, do something simple and fast:
lines_in_file = 0
File.foreach(some_file) { lines_in_file += 1 }
After running that, lines_in_file will contain the number of lines read. Memory won't be impacted and it'll run like blue blazes on huge files.
How can I test whether a sentence (combination of four or five words) is displayed in a single line?
I have to search with a name or some other fields. After search results are displayed, I should test whether the displayed text is a single line. For example, the code below is used to verify the search result link:
//ol[contains(#class,'search results')]/li[contains(#class,'mod result') and contains(#class,'XXXXXX')]//a[contains(#href,'trk=XXXXXX')]
I am not familiar with ruby, but the following java approach should work in any language.
Assuming that your "sentence" is entirely contained in one element, you could find all occurrences with something like:
driver.findElements(By.xpath("//*[text()='your sentence']"))
Then simply test for the size of the array.
Assuming that a single or multiple lines will be contained within a single DOM element, you could use the vertical component of the element size to check for the multiple line condition.
webElement.getSize()
I have a file that is comma delimited
Text File:
"some_key_1", "Translation 1"
"some_key_2", "Translation 2"
"some_key_3", "Translation 3"
"some_key_4", "Translation 4"
"some_key_5", "I am a very long line of text that has decided to cause an issue for the programmer, I have thus far laughed at his futile attempts to fix me."
Private Sub ImportFile()
Dim strEmpFileName As String
Dim intEmpFileNbr As Integer
Dim strTranslationKey As String
Dim strTranslation As String
Dim error As String
strEmpFileName = "C:\Files\test_file_1.asp"
intEmpFileNbr = FreeFile
Open strEmpFileName For Input As #intEmpFileNbr
Do Until EOF(intEmpFileNbr)
Input #intEmpFileNbr, strTranslationKey, strTranslation
Loop
End Sub
The code assigns the lines of text just fine until it gets to some_key_5, even tho there it thinks the text on a new line even tho it is a new line because of word wrap and not me hitting enter.
Is there any way around this? Shortening the line is not really an option.
I think the likely problem is the comma in the translation element. I'd suggest your best bet is probably to read the file with the
Line Input #my_file, my_string
statement and pick it apart by hand. See here for more.
You can use regular expression to match all strings inside "", and then put them into pairs.
As for line breaks, you can simply replace all of them to empty string before doing a regexp match.
Most likely you have a line termination issue, and you actully have a CR where it stops reading. I would suggest recreating the file using notepad, or looking at it with a text editor with a hex mode (that might tell you if you have a really long line as as well, if your real file has a line that exceeds a few K it might actually be a problem).
I ran your code against your supplied data, with a msgbox giving the length and right 10 characters of the string, and it worked. It also worked when I increased the field length of the second part to 721 chars.
I opted to use the file system object and it works just fine with the same data. It couldn't have been the comma, as it would attach the data from the file to the variable just fine, and include information past the comma. It would then add the item on the next line as a new key. I couldn't get past this, tried even removing the commas from the offending item and it would still break. But after I switched it to the file system object, it works just fine with the same data, i just have to manually split it.