Char edit in a text box

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 1318 Views - Last Post: 11 February 2013 - 09:55 PM Rate Topic: -----

#16 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3458
  • View blog
  • Posts: 11,707
  • Joined: 12-December 12

Re: Char edit in a text box

Posted 09 February 2013 - 01:11 PM

Yeah, you can only have looked at this for a maximum of 16 minutes. Put in two or three hours of effort :) and then come back showing your code.
Was This Post Helpful? 0
  • +
  • -

#17 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Char edit in a text box

Posted 10 February 2013 - 10:07 AM

Why isn't anyone recommending the Replace function?
Debug.Print Replace("Red Roses", "R", "010_")
will give "010_ed 010_oses" as a result. You can just put all the characters and replacement strings in a 2-dimensional array and iterate through it, replacing as you go. You can then do the reverse to retrieve the plaintext. IMHO, Dictionary is a bit dramatic for storing less than 100 key/value pairs, and Collection is more so. There's no appreciable performance overhead in iterating 100 array elements, so I don't see a reason to add another DLL reference to the project.

Maj, as Andrew says, Dictionary is a more lightweight way than Collection to store key/value pairs. It's useful to think of it as a predecessor to the Generic List object in .Net. I use them in place of Collections whenever I can.

This post has been edited by BobRodes: 10 February 2013 - 10:08 AM

Was This Post Helpful? 0
  • +
  • -

#18 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3458
  • View blog
  • Posts: 11,707
  • Joined: 12-December 12

Re: Char edit in a text box

Posted 10 February 2013 - 10:27 AM

Replace also avoids the issue mentioned in a previous post of mine. That is, if the OP loops through every character then he would have to keep track of each number until he finds, for example, "010", before he can substitute a letter.

There remains a slight issue with, for example, "1" and "01" though. The OP would have to make sure that he replaces "01" before attempting to replace "1".

This post has been edited by andrewsw: 10 February 2013 - 10:29 AM

Was This Post Helpful? 0
  • +
  • -

#19 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Char edit in a text box

Posted 10 February 2013 - 10:44 AM

View Postandrewsw, on 10 February 2013 - 11:27 AM, said:

Replace also avoids the issue mentioned in a previous post of mine. That is, if the OP loops through every character then he would have to keep track of each number until he finds, for example, "010", before he can substitute a letter.

There remains a slight issue with, for example, "1" and "01" though. The OP would have to make sure that he replaces "01" before attempting to replace "1".

Yeah, back in VB4 before the Replace function was available, that sort of thing was a pain in the neck! The issue you mention can be handled by using an underscore character on both ends: Replace("R", _010_) would solve this problem without having to keep track of any sort of replacements made. Which, as I am sure you agree, is fervently to be desired. :)

This post has been edited by BobRodes: 10 February 2013 - 10:45 AM

Was This Post Helpful? 0
  • +
  • -

#20 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3458
  • View blog
  • Posts: 11,707
  • Joined: 12-December 12

Re: Char edit in a text box

Posted 10 February 2013 - 11:33 AM

Replace("R", "_010_")
assuming the OP is happy to introduce the underscores..(?) but I'm not particularly fervent about this topic :) (Good word of the day!). Or even febrile!

This post has been edited by andrewsw: 10 February 2013 - 11:36 AM

Was This Post Helpful? 0
  • +
  • -

#21 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Char edit in a text box

Posted 11 February 2013 - 06:57 PM

Quote

assuming the OP is happy to introduce the underscores..(?)


It's true, we would have to have access to the SME to uncover that.
Was This Post Helpful? 0
  • +
  • -

#22 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3458
  • View blog
  • Posts: 11,707
  • Joined: 12-December 12

Re: Char edit in a text box

Posted 11 February 2013 - 07:01 PM

View PostBobRodes, on 11 February 2013 - 06:57 PM, said:

It's true, we would have to have access to the SME to uncover that.

SME? Subject Matter Expert..?
Was This Post Helpful? 0
  • +
  • -

#23 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Char edit in a text box

Posted 11 February 2013 - 09:55 PM

View Postandrewsw, on 11 February 2013 - 08:01 PM, said:

SME? Subject Matter Expert..?
Yup. In this case, the OP is the SME. Like most SME's, we'll never hear from him until we have implemented the requirements and he says but...but...why did you do x? I wanted y. The fact that I signed a document saying I wanted x is irrelevant, given that I wanted y.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2