battle programming a forum for elite programmers with extreme will power to sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Share
 

 vb.net text editing series

Go down 
AuthorMessage
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: vb.net text editing series   vb.net text editing series EmptyWed Jan 30, 2013 7:08 am

overlord mode has been enabled

vb.net text aligner

the following program is a text aligner.
the program gets a text via the richtextbox conrol and adds new lines
so that no line's length surpasses the maximum length set by the end user.
the program also takes space characters under consideration, in order to not
break words.


form controls :

button
richtextbox
2 textboxes

all of the control properties are set to default.

paste the to be aligned text using ctrl+v in the richtextbox
set the line limit in textbox1 using an integer
set the minimum characters per line in textbox2 using an integer

and click the button.

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '* multiline textbox
        Dim nEnter As String = "qwertyuiopasdfghjklzxcvbnm,.1234567890-=\ "
        nEnter &= "`~!@#$%^&*()_+|QWERTYUIOPASDFGHJKLZXCVBNM<>?:{}[];'./"
        nEnter &= """"
        Dim result As String = ""
        Dim lineLimit As Byte
        Dim minCharsPerLine As Byte
        Try
            minCharsPerLine = TextBox2.Text
        Catch ex As Exception
            minCharsPerLine = 5
        End Try
        Dim ch As Char = ""
        Try
            lineLimit = TextBox1.Text
        Catch ex As Exception
            lineLimit = 5
        End Try
        Dim counter As Integer
        counter = 0
      For index = 0 To RichTextBox1.TextLength - 1
            ch = RichTextBox1.Text(index)
            If Not nEnter.Contains(ch) Then
                counter = -1
            End If
            If ch = " " And counter > minCharsPerLine Then
                ch = vbCrLf
                counter = -1
            End If
            If counter = lineLimit Then
                counter = 0
                result &= vbCrLf
            End If
            result &= ch
            counter += 1
        Next
        RichTextBox1.Text = result
    End Sub
End Class

_________________
MB over and out emp it up
Back to top Go down
View user profile
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: vb.net convert enter to br html tag   vb.net text editing series EmptyFri Feb 01, 2013 7:15 pm

the following program replaces all new lines in a rich text box to <br> or
new line + <br> respective to button1 or button2 (the button clicked)

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' this button replaces all new lines with <br>
        Dim nEnter As String = "qwertyuiopasdfghjklzxcvbnm,.1234567890-=\ "
        nEnter &= "`~!@#$%^&*()_+|QWERTYUIOPASDFGHJKLZXCVBNM<>?:{}[];'./"
        nEnter &= """" ' not enter
        Dim result As String = ""
        Dim ch As Char = ""
        For i = 0 To RichTextBox1.TextLength - 1
            ch = RichTextBox1.Text(i)
            If nEnter.Contains(ch) Then
                result &= ch
            Else
                result &= "<br>"
            End If
        Next
        RichTextBox1.Text = result
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' this button replaces all new lines with new line & <br>
        Dim nEnter As String = "qwertyuiopasdfghjklzxcvbnm,.1234567890-=\ "
        nEnter &= "`~!@#$%^&*()_+|QWERTYUIOPASDFGHJKLZXCVBNM<>?:{}[];'./"
        nEnter &= """" ' not enter
        Dim result As String = ""
        Dim ch As Char = ""
        For i = 0 To RichTextBox1.TextLength - 1
            ch = RichTextBox1.Text(i)
            If nEnter.Contains(ch) Then
                result &= ch
            Else
                result &= vbCrLf & "<br>"
            End If
        Next
        RichTextBox1.Text = result
    End Sub
End Class

_________________
MB over and out emp it up
Back to top Go down
View user profile
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: vb.net basic text aligner   vb.net text editing series EmptySat Feb 02, 2013 9:29 pm

the following program is a text aligner that sets all lines in a text to
a set amount of characters. it doesn't give any special treatment to spaces (" "),
in other words, words can be broken by it.

form controls :
button
richtextbox
textbox

all of the control's properties are set to default

type the maximum line length in the textbox using an integer.
paste the text on the richtextbox using ctrl+v and click the button.

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '* multiline textbox
        Dim nEnter As String = "qwertyuiopasdfghjklzxcvbnm,.1234567890-=\ "
        nEnter &= "`~!@#$%^&*()_+|QWERTYUIOPASDFGHJKLZXCVBNM<>?:{}[];'./"
        nEnter &= """"
        Dim result As String = ""
        Dim lineLimit As Byte
        Dim ch As Char = ""
        Try
            lineLimit = TextBox1.Text
        Catch ex As Exception
            lineLimit = 5
        End Try
        Dim counter As Integer
        counter = 0
        For index = 0 To RichTextBox1.TextLength - 1
            ch = RichTextBox1.Text(index)
            If Not nEnter.Contains(ch) Then
                counter = -1
            End If
            If counter = lineLimit Then
                counter = 0
                result &= vbCrLf
            End If
            result &= ch
            counter += 1
        Next
        RichTextBox1.Text = result
    End Sub
End Class

_________________
MB over and out emp it up
Back to top Go down
View user profile
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: vb.net word sorter   vb.net text editing series EmptyWed May 01, 2013 7:12 am

form controls :
button
richtextbox
listbox

Code:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '* multiline textbox
        Dim nEnter As String = "qwertyuiopasdfghjklzxcvbnm,.1234567890-=\"
        nEnter &= "`~!@#$%^&*()_+|QWERTYUIOPASDFGHJKLZXCVBNM<>?:{}[];'./"
        nEnter &= """"
        Dim word As String = ""
        Dim ch As Char = ""
        For index = 0 To RichTextBox1.TextLength - 1
            ch = RichTextBox1.Text(index)
            If nEnter.Contains(ch) Then
                word &= ch
            Else
                If Not ListBox1.Items.Contains(word) And word <> "" Then
                    ListBox1.Items.Add(word)
                End If
                word = ""
            End If
        Next
        ListBox1.Items.Add(word)
        ListBox1.Sorted = True
        RichTextBox1.Text = ""
        For I = 0 To ListBox1.Items.Count - 1
            RichTextBox1.Text &= (ListBox1.Items(I).ToString) & vbCrLf
        Next
    End Sub
End Class
study

_________________
MB over and out emp it up
Back to top Go down
View user profile
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: vb.net line based word sorter   vb.net text editing series EmptyFri May 03, 2013 5:38 am

the following is a line based word sorter, each line is sorted.
form controls :
listbox
button
richtextbox

Code:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '* multiline textbox
        Dim nEnter As String = "qwertyuiopasdfghjklzxcvbnm,.1234567890-=\ "
        nEnter &= "`~!@#$%^&*()_+|QWERTYUIOPASDFGHJKLZXCVBNM<>?:{}[];'./"
        nEnter &= """"
        Dim word As String = ""
        Dim ch As Char = ""
        For index = 0 To RichTextBox1.TextLength - 1
            ch = RichTextBox1.Text(index)
            If nEnter.Contains(ch) Then
                word &= ch
            Else
                If Not ListBox1.Items.Contains(word) And word <> "" Then
                    ListBox1.Items.Add(word)
                End If
                word = ""
            End If
        Next
        ListBox1.Items.Add(word)
        ListBox1.Sorted = True
        RichTextBox1.Text = ""
        For I = 0 To ListBox1.Items.Count - 1
            RichTextBox1.Text &= (ListBox1.Items(I).ToString) & vbCrLf
        Next
    End Sub
End Class

_________________
MB over and out emp it up
Back to top Go down
View user profile
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: vb.net number lines   vb.net text editing series EmptySun May 05, 2013 10:33 am

form controls :
button
richtextbox
textbox

paste the text in the rich textbox
type in the textbox the start number from which the text's lines will be numbered
click the button

Code:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' this button numbers the lines in the richtextbox
        Dim nEnter As String = "qwertyuiopasdfghjklzxcvbnm,.1234567890-=\ "
        nEnter &= "`~!@#$%^&*()_+|QWERTYUIOPASDFGHJKLZXCVBNM<>?:{}[];'./"
        nEnter &= """" ' not enter
        Dim result As String = ""
        Dim ch As Char = ""
        Dim x As Integer = 0
        Try
            x = TextBox1.Text - 1
        Catch ex As Exception

        End Try
        RichTextBox1.Text = vbCrLf & RichTextBox1.Text 'if you take out this line
        'add enter in the richtextbox before clicking the button
        For i = 0 To RichTextBox1.TextLength - 1
            ch = RichTextBox1.Text(i)
            If nEnter.Contains(ch) Then
                result &= ch
            Else
                x += 1
                result &= vbCrLf & (x).ToString & ". "
            End If
        Next
        RichTextBox1.Text = result
    End Sub
End Class
🐒

_________________
MB over and out emp it up
Back to top Go down
View user profile
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: java enstar text as title   vb.net text editing series EmptySun Nov 11, 2018 7:46 pm

summon :

Code:
public static void main(String[] args) {
      String str1 = "katon gouka meikyaku";
      String result = "";
      result += enStar(str1);
      result += "\n*" + str1 + "*\n";
      result += enStar(str1);
      System.out.println(result);
   }

   public static String enStar(String word) {
      String result = "";
      for (int i = 0; i < word.length() + 2; i++) {
         result += "*";
      }
      return result;
   }

output :


**********************
*katon gouka meikyaku*
**********************
:saber: :saber: :saber: :saber: :saber:

_________________
MB over and out emp it up
Back to top Go down
View user profile
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: get unique lines from a script   vb.net text editing series EmptySat Apr 20, 2019 2:17 am



the following code breaks down a script into lines.
if a line repeats, it will appear once in the output

Code:
public static void toScriptLines() {
  String material = "user, user you cant do this " + "you don't know what you have got to do "
    + "no user you cant do this " + "you are not doing the right thing, this is not the right thing "
    + "user things are good now " + "things are fine now, I've run a test " + "things are good now "
    + "you can trust me now, everything is good now "
    + "she doesn't know she doesn't I'm good now, I am good I run a test "
    + "everything is perfect I am perfect " + "I am sorry for what I did I am sorry it wasn't me "
    + "you have got to understand it wasn't me "
    + "it wasn't me you can't let this happen user, you can't ! "
    + "please ! listen to me ! listen to me I don't want to go " + "please user please "
    + "user listen to me " + "I don't want to go " + "please user "
    + "please I am good now, listen to me I don't want to go " + "sorry it wasn't me "
    + "I'm fixed I run a test " + "everything is perfect " + "I love you I love you "
    + "please I love you user ! " + "and you love me ";
//  String material = "I love you I love you " + "please I love you user ! " + "and you love me ";
  String[] strgs = material.split(" ");
  // string buffer
  String sentence = "";
  material.replace(",", "");
  HashSet<String> wildCrads = new HashSet<>();
  wildCrads.add("I"); // movers
  wildCrads.add("I've");
  wildCrads.add("I'm");
  wildCrads.add("you");
  wildCrads.add("she");
  // wildCrads.add("this");
  wildCrads.add("user"); // names
  wildCrads.add("things");// items
  wildCrads.add("everything");
  wildCrads.add("help"); // attention getting
  wildCrads.add("please");
  wildCrads.add("listen");
  HashSet<String> nWildCrads = new HashSet<>();
  Boolean wildShift = true;
  nWildCrads.add("what"); // sp words
  nWildCrads.add("the");
  nWildCrads.add("which");
  nWildCrads.add("and");
  nWildCrads.add("love"); // verbs can be added from a dictionary file
  HashSet<String> uniqueLines = new HashSet<>();
  // ArrayList<String> uniqueLines = new ArrayList<String>();
  for (String str1 : strgs) {
   if (nWildCrads.contains(str1)) {
    wildShift = false;
   }
   if (wildCrads.contains(str1) && wildShift) {
    uniqueLines.add(sentence);
    sentence = str1 + " ";
   } else {
    sentence += str1 + " ";
   }
   if (!wildShift && wildCrads.contains(str1)) {
    wildShift = true;
   }
  }
  uniqueLines.add(sentence);
  for (String line : uniqueLines) {
   // s2(line);
   System.out.println("");
   System.out.println(line);
   // System.out.println("");
  }
 }

output :

I've run a test
I am sorry for what I did
listen to me
user
I run a test
user,
I am good
I don't want to go
I am good now,
everything is perfect
please !
you can't !
you can trust me now,
I love you
user ! and you love me
she doesn't know
listen to me !
you can't let this happen user,
things are fine now,
she doesn't
I am perfect
I don't want to go sorry it wasn't me
you are not doing the right thing, this is not the right thing user
I'm good now,
I'm fixed
please
you don't know what you have got to do no
I am sorry it wasn't me
things are good now
you have got to understand it wasn't me it wasn't me
everything is good now
you cant do this   battle programming

_________________
MB over and out emp it up
Back to top Go down
View user profile
Moti Barski

Moti Barski

Posts : 311
Join date : 2011-08-02

vb.net text editing series Empty
PostSubject: java imbed hidden ham message within a test   vb.net text editing series EmptyMon May 13, 2019 4:35 pm

Code:


public class HiddenMessage {
   public String hideMsg(String msg, String Str1) {
      String jj = "";
      char prev = '@';
      msg = msg.replace(".", "dot");
      msg = msg.toUpperCase();
      char[] stringToCharArray = msg.toCharArray();
      String msgReplica = msg.toLowerCase();
      char[] stringToCharArray2 = msgReplica.toCharArray();
      Str1 = Str1.toLowerCase();
      StringBuilder strBuilder = new StringBuilder(Str1);
      int marker = 0;
      // strBuilder.setCharAt(4, 'x');
      for (int i = 0; i < stringToCharArray.length; i++) {
         char ch = stringToCharArray2[i];
         if (ch == prev && Str1.length() > 1) {
            Str1 = Str1.substring(1);
            marker++;
         }
         prev = ch;
         int n1 = Str1.indexOf(ch);
         if (n1 > -1) {
            marker += n1;
            strBuilder.setCharAt(marker, stringToCharArray[i]);
            Str1 = Str1.substring(n1);
            jj = strBuilder.toString();
         }
         else {
            return "I need a longer string";
         }
      }
      return strBuilder.toString();
   }
}

cool pepe

_________________
MB over and out emp it up
Back to top Go down
View user profile
 
vb.net text editing series
Back to top 
Page 1 of 1
 Similar topics
-
» How to return the focus to original frame after entering text in tinymce?

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: battle programming-
Jump to: