How To Make a Line Break/New Line in Java

How To Make a Line Break/New Line in Java
Line Break or New Line : I hope you understand what it is, in HTML you use <br> tag to make a new line so in Java if you want to make a new line it's not that hard but it has several methods depends on the platform.

Coming to the point, most of the java beginners think this is the one and only way to make a new line : System.out.println("\n"); but It's not true.. let me tell you something you might think that whatever you program using java will work on other java supported platforms, YES! they will work on other platforms but there are few things that has to be changed in order to get the functions work.. for example this tutorial; this line of code : System.out.println("\n"); would make a new line only on Windows. As I said before there are few things that are different from platform to platforms.

If you want to make a new line on Mac you must use this : System.out.println("\r"); and for Linux you have to use this : System.out.println("\r\n");. So I came up with something that works on all the platforms, It's pretty simple and works perfectly.

First you need to make a public string and set the value to make a new line(You can also just make normal string and set the value)
Add this line of code before your main event
public static String breakline = System.getProperty("line.separator");

Whenever you need to make a new line just use this line of code 
You can add this wherever you want to
System.out.println(breakline);

Please comment if you have any doubts..!

How To Read A Text File Hosted Online To A String

 How To Read A TXT File Hosted Online To A String
So I got a email asking how to do this, I haven't done this before so went through some Google searches and found how to do this. It was pretty easy. I'll just share the code here maybe it'll be useful for someone.

You need these namespaces :
Imports System.IO
Imports System.Net

Event :
Dim TXT As String = "http://www.ultimateprogrammingtutorials.info/robots.txt"
Dim WC As WebClient = New WebClient()
Dim Read As StreamReader = New StreamReader(WC.OpenRead(TXT))
Dim STR As String = Read.ReadToEnd
TextBox1.Text = STR

  • Replace the TXT string value with your .txt link. 
  • You can also write into a richtextbox or whatever you want(I used textbox1 for example) 
I hope you learned something from this snippet.

How To Check If Directory Exists In VB.NET And C#

directory in programming
I have had some hard times in solving this problem not these days but sometime ago when I started programming so I think this would be helpful for anyone who has started programming..

Here's the code to check if the directory exists in VB.NET :

Try
            If System.IO.Directory.GetDirectories("PATH").Length > 0 Then
                MsgBox("directory exists")

            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

All you need to do is replace PATH with the directory you want to check... length > 0 identifies if the directory exists.

Here's the code for C# :

try
            {
                if (System.IO.Directory.GetDirectories("PATH").Length > 0)
                {
                    MessageBox.Show("directory exists");

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Do the same thing as given for VB.NET code.

Snippet : Using Regular Expressions in Java

This snippet helps you to use Regular Expression(Regex) in Java.

Snippet : Get ASCII Value For Every Characters

This snippet helps you to get the ASCII value for every characters.

Snippet : Detect TOR in PHP

This snippet helps you to detect TOR network connection in PHP

Snippet : Javascript onmouseover and onmouseout

This snippet helps you to make buttons etc.. I have been using this for Download Buttons.

Snippet : Generate Random Password

This snippet helps you to Generate Random Password

Snippet : Base64 Encode and Base64 Decode in PHP

This snippet helps you to encode and decode your text with base64.
Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding. - Wikipedia

Snippet : TinyURL API in PHP

This snippet helps you to shorten your URLs with TinyURL API(Function with usage)

  1. <?php
  2. function TinyURL($url){
  3.     return file_get_contents('http://tinyurl.com/api-create.php?url='.$url);
  4. }
  5. echo TinyURL('http://www.ultimateprogrammingtutorials.info');
  6. ?>
You need to replace http://www.ultimateprogrammingtutorials.info with the URL you want to shorten

Snippet : HTTP Redirection In PHP

This snippet helps you to redirect to another website/webpage.


  1. <?php
  2.     header('Location: http://www.example.com');
  3. ?>
Replace http://www.example.com with your website URL/webpage URL

Snippet : Detect HTTP User Agent in PHP

The code below helps you to detect the HTTP user agent I mean the browser version.


  1. <?php           
  2.     $useragent = $_SERVER['HTTP_USER_AGENT'];
  3.     echo "<b>User Agent </b>: ".$useragent;
  4. ?>
Return

User Agent : Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36

Useful Snippets For C#

Opening another form

new Form2().Show();

Minimize Form 

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;

Maximize Form

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

Copy A File

File.Copy("C://program files/test.txt", dialog.FileName);

Delete A File

File.Delete("C://program files/test.txt");

Open A Website

System.Diagnostics.Process.Start("http://www.ultimateprogrammingtutorials.blogspot.com");