Why 'New Line' takes two characters? - vb.net

I made a .txt file (UTF-8) and put the following text in it:
123
456
789
I then tried to find out the position of the character '4' by using the InStr() function. Surprisingly, the result was 6. I tried with the character '3', and the result was 3. So, there must be two characters in between the 3 and the 4.
I then tried InStr(TextBox1.Text, Chr(13)) and the result was 4.
Ok. The "New Line" has a character located in the 4th position. If so, then what is 5th character in there?

The actual character(s) used for new-line are different from one platform to the next. Some systems use character 13 to mean a new-line, some use 10, and some, like Windows, use both.
Technically, character 13 is supposed to mean a carriage return (return the print head of the printer to the left side of the page), that's why it's often referred to as CR. Remember, in the early days of computing, printers were used as terminals rather than video screens. So, the closest equivalent of CR on a video terminal is for the cursor to return to the beginning of the current line, but not advance to the next line.
Character 10 means line-feed (LF), which means to advance (i.e. feed) the paper by one line so that the print head is ready to print on the next line. The closest equivalent to a line-feed on a video terminal is to move the cursor down to the next line, but keep it at the same x-position.
So, with those two-things in mind, if you wanted to begin typing at the beginning of the next line, you would need to do both things. You need to advance to the next line on the page AND return to the beginning of the line, hence CRLF, two characters.
Presumably, some system designers thought it was too wasteful to use two characters for each new-line, when the added nuance was rarely needed for computers with video displays, so they opted to only use either CR or LF. Since the correct encoding to use changes from one platform to another, it's best to use Environment.NewLine in .NET to get whichever is appropriate for the current system.
Consider, for example, when you run this console app on windows:
Public Sub Main()
Console.Write("123" & vbCr)
Console.Write("4" & vbCr)
End Sub
The output is:
423
The carriage-return only caused the cursor to go back to the beginning of the line. It didn't cause it to move down to the next line, so the 4, when it's printed, overwrites the 1.

Related

C Programming Format Adjustment

I am asking for some homework help. I am not asking for the answer,I just wanted to be pointed in the right direction.
I have a program in C which I am new to. I have to recreate a Unix tool using vi. Its job will be to read input and “neaten” it up. It reads in paragraphs of words and rearranges them such that they fit nicely onto a line of specified width, inserting line breaks as needed. A paragraph is separated from other paragraphs by one or more empty lines than changing the width with -w and changing to right alignment using -r.
Next would be to justify the text using -j so that every line with more than one word extends from the left to the right with max width. I need to apply integer division to calculate the total number of spaces that should have been seen by the time you finish a gap using Kevin Woods Si = i*S/G where S is the total number of spaces needed in the line, G is the number of gaps between words in the line and Si is the number of spaces that should have appeared by the end of the i'th gap. Lastly suppress line spacing from lines entered with more than a double line back into a double line.
The options should be cumulative—I can specify width, alignment, and skipping of blank lines together. The -r and -j flags should not be used together.
first step: metacode
main(arguments)
analyse arguments f.e. with getopt() for correctness and validity
read the original text
break the text into virtual paragraphs (identified by a double LineBreak)
for each paragraph
break it into lines of less than allowed (-w, default 80) characters
for each line that is not the last line of a paragraph
fill with spaces according to your algorithm and command line spezification
print out all lines
second step: coding
this is your task. Please come back, when you have code, that shows us, where you are stuck.

Visual Basic pulling a character from a certain line number

I am working on a macro that needs to be able to check and make sure that a character on a certain line is what it should be before it finishes the form.
Where or how do i find the information to do this?
I have tried using the command "Left(#of line ,1)" and am not getting it to return anything at this point.
I Assume that you have this text in a string. Comment to my answer if wrong.
You can use a Regex to compare to string with your character like so :
If Regex.IsMatch(MyString, *.{X}Y) Then
'You have to manually replace X for the number of characters before the character you scan for
'You have to manually replace Y for the-said character it is supposed to be
Look at http://www.codeproject.com/Articles/9099/The-Minute-Regex-Tutorial for more info on Regex.
If you want to only take one line in your string :
TheLine = split(MyString,Environnement.Newline)([Line Number])

When I paste a string into Xcode I always get an error and have to re-type it

This happens every time I paste a line of code containing a string into Xcode. for example when I pasted this into Xcode:
simonLabel.text = #"Good Job!";
I received an error saying that there was an "unexpeceted '#' in program"
If I delete everything and retype exactly the way I pasted it I do not get an error.
There are too many problems that can appear there:
" can be a different character that you expect
(space) can be a different character that you expect
invisible characters. Something you won't see in the editor at all but they got there with the copy-paste.
All these problems can happen because
You copy it from a website with different encoding (or from a really badly writter website)
You copy it from a smart editor (e.g. MS Word, Open Office) which replaces some of the characters to match locale (e.g. quotation marks) or replaces/add spaces based on grammar and word wrapping (e.g non-breaking space).

How to paste text to end of every line? Sublime 2

I'm curious if there is a way to paste text to the end of every line in Sublime 2? And conversely, to the beginning of every line.
test line one
test line two
test line three
test line four
...
Say you have 100 lines of text in the editor, and you want to paste quotation marks to the beginning and end of each line.
Is there an easy way to do this or a plugin that anyone would know of? This would often save me a lot of time on various projects.
Thanks.
Yeah Regex is cool, but there are other alternative.
Select all the lines you want to prefix or suffix
Goto menu Selection -> Split into Lines (Cmd/Ctrl + Shift + L)
This allows you to edit multiple lines at once. Now you can add *Quotes (") or anything * at start and end of each lines.
Here's the workflow I use all the time, using the keyboard only
Ctrl/Cmd + A Select All
Ctrl/Cmd + Shift + L Split into Lines
' Surround every line with quotes
Note that this doesn't work if there are blank lines in the selection.
Select all the lines on which you want to add prefix or suffix. (But if you want to add prefix or suffix to only specific lines, you can use ctrl+Left mouse button to create multiple cursors.)
Push Ctrl+Shift+L.
Push Home key and add prefix.
Push End key and add suffix.
Note, disable wordwrap, otherwise it will not work properly if your lines are longer than sublime's width.
Let's say you have these lines of code:
test line one
test line two
test line three
test line four
Using Search and Replace Ctrl+H with Regex let's find this: ^ and replace it with ", we'll have this:
"test line one
"test line two
"test line three
"test line four
Now let's search this: $ and replace it with ", now we'll have this:
"test line one"
"test line two"
"test line three"
"test line four"
You can use the Search & Replace feature with this regex ^([\w\d\_\.\s\-]*)$ to find text and the replaced text is "$1".
Use column selection. Column selection is one of the unique features of Sublime2; it is used to give you multiple matched cursors (tutorial here). To get multiple cursors, do one of the following:
Mouse:
Hold down the shift (Windows/Linux) or option key (Mac) while selecting a region with the mouse.
Clicking middle mouse button (or scroll) will select as a column also.
Keyboard:
Select the desired region.
Type control+shift+L (Windows/Linux) or command+shift+L (Mac)
You now have multiple lines selected, so you could type a quotation mark at the beginning and end of each line. It would be better to take advantage of Sublime's capabilities, and just type ". When you do this, Sublime automatically quotes the selected text.
Type esc to exit multiple cursor mode.
Select all lines you want to add a suffix or prefix.(command+ A to select all the lines)
Press command+shift+L. This will put one cursor at the end of every line and all the selected lines would still be selected.
For adding suffix press command+right and for adding prefix command+left. This will deselect all the earlier selected text and there will only be cursors at the end or start of every line.
Add required text

how to break up lines of codes AND comments in VB.NET 2010?

everytime i try the space then underscore + enter it doesnt work and it lights up red
edit - like for example this is a comment:
'you must add such and such to this variable and then you must declare it'
say i have that for a comment and i want to break the comment after variable. when i do this
'you must add such and such to this variable _
and then you must declare it'
it gives me an error
The underscore at the end of the line trick doesn't work for comments. The underscores are treated as part of the comment.
To create a bunch of single line comments at once, select the lines you want to comment out and press CTRL+K then CTRL+C
A line continuation consists of at least one white-space character that immediately precedes a single underscore character as the last character (other than white space) in a text line.
Ref.
Doesn't apply to comments though; if you want multiple comment lines simply start a new comment for each subsequent line.