-
Oct 21st, 2014, 12:18 AM
#1
Thread Starter
Lively Member
Inserting character to the left of a string
Hi guys,
I'm trying to insert a character to the left for a right to left writing, similar to the Arabic style.
Here's the code:
vb.net Code:
Dim Cache As String Dim memory As Integer = 0 Public Sub TextOutput(ByVal Character As String) '/////////////////////////// Cache = TextBox1.Text Dim Memory As Integer = TextBox1.SelectionStart TextBox1.Text = Cache.Insert(Memory, Character) TextBox1.SelectionStart = Memory End Sub
The thing is, I'm using this method do that I can insert a character I missed during typing. However the direction of the string goes from left to right. How do I go around this?
Thanks.
Vizier87.
-
Oct 21st, 2014, 12:34 AM
#2
Re: Inserting character to the left of a string
The `startIndex` parameter of the String.Insert method specifies the index of the character BEFORE which you want to insert the value. If you want to insert AFTER a particular character then that is BEFORE the NEXT character, so simply add 1 to the index.
-
Oct 21st, 2014, 02:56 AM
#3
Thread Starter
Lively Member
Re: Inserting character to the left of a string
Hi JMC,
I tried this:
vb.net Code:
If Memory = 0 Then TextBox1.Text = Cache.Insert(Memory, Character) End If If Memory > 0 Then TextBox1.Text = Cache.Insert(Memory + 1, Character) End If
But the text direction was still adding to the right. What did I miss?
-
Oct 21st, 2014, 05:57 PM
#4
Re: Inserting character to the left of a string
If I understood, you want to add a character at middle of text, right?
Try this:
Code:
TextBox1.Text = TextBox1.Text.Insert(TextBox1.SelectionStart, "a")
Last edited by omundodogabriel; Oct 21st, 2014 at 06:02 PM.
-
Oct 27th, 2014, 01:28 AM
#5
Thread Starter
Lively Member
Re: Inserting character to the left of a string
Originally Posted by omundodogabriel
If I understood, you want to add a character at middle of text, right?
Try this:
Code:
TextBox1.Text = TextBox1.Text.Insert(TextBox1.SelectionStart, "a")
Hi Gabriel, thanks for the input. However, my objective is on the Right-to-Left method of writing characters, so when I want to key in characters "t", "e", "s" and "t" it would appear as "tset" rather than "test". Seems that the insert method only allows keying in characters from left to right?
-
Oct 27th, 2014, 06:39 AM
#6
Re: Inserting character to the left of a string
Right because that's how most languages work... left to right...
So to go "right to left" - character by character - you have to code for that... usually by changing where the insert point it, by resetting it to the beginning.
All you should need to to is in the text changed event is to set the SelectionStart property to 0... so each time the user types something, the text changes and the cursor moves to the front of the textbox, allowing the next character to be inserted to the left.
You probably also will want to change the alignment on the text box too.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|