• 0

[VB.NET] Scrambling text between the first and last letter


Question

3 answers to this question

Recommended Posts

  • 0

Take a look at StrReverse http://msdn.microsoft.com/en-us/library/e462ax87(VS.71).aspx You can get the length of the string

Dim sValue as String = "Scramble"

Dim iLength as Int16 = sValue.Length

And then decided how many characters you want to reverse. Multiple runs through StrReverse will get you want you want. (Though I cant see the value of this. Please please please tell me this is not a password issue)

  • 0

Are you trying to produce something like this:

"Plesae use the floilonwg foramt wehn saintrtg a new toipc taht reaetls to a sinlge ponmgamirrg lnagague"

I've put together a VB2008 Project for you to demonstate how this can be achieved. The general premise is:

  1. Break down the sentence into its component words.
  2. For each word store its internal component characters (between the first and last letter).
  3. Swap the letters of these internal components.
  4. Re-write the word, preserving the first and last letters, with the swapped letters internally.

You need to utilise a few char arrays, and then a simple scrambling function:

Private Function ScrambleWord(ByVal word As String) As String
	Dim i As Integer = 0
	Dim builder As System.Text.StringBuilder = New System.Text.StringBuilder()
	Dim random As Random = New Random()
	Dim index As Integer = 0

	Dim lower As Integer = 0
	Dim upper As Integer = 0

	Dim parts() As Char
	Dim part As Char

	If Not (String.IsNullOrEmpty(word)) Then
		If (word.Length > 3) Then
			parts = word.ToCharArray()
			builder.Append(word.Substring(0, 1))
			parts = word.Substring(1, word.Length - 2).ToCharArray()

			lower = LBound(parts) : upper = UBound(parts)
			For i = lower To upper
				index = random.Next(lower, upper)
				part = parts(index)
				parts(index) = parts(i)
				parts(i) = part
			Next
			builder.Append(parts)
			builder.Append(word.Substring(word.Length - 1, 1))
			Return builder.ToString()
		Else
			Return word
		End If
	Else
		Return String.Empty
	End If
End Function

post-92970-1233934476.jpg

Find the project attached. Hope that helps :)

WordScrambler___VB2008.zipFetching info...

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • This is why you NEVER use AI for development unless you are intelligent enough to know what it is doing.   100% the developer's fault.
    • im an MS fanboy and even this is hilarious to me... so many issues with 24h2, how can MS say this with a straight face?
    • Every vendor does this. Its just software dev. Do you release a current set or fixes or wait for them all? What if those fixes are taking really long?
    • Google Drive videos finally get thumbnail previews, but there's a big caveat by Usama Jawad Google Drive is a pretty decent cloud storage solution, especially if you're well-invested in Google's ecosystem. If you use an Android phone, you've probably used Google Drive to store your media content, emails, and WhatsApp backups. Just a couple of weeks ago, Google announced a UI revamp for its desktop sync client for Drive, and while it has announced a much smaller feature today, it's definitely quite handy. Videos stored on Google Drive are finally getting thumbnail previews. This means that if you hover your mouse over the progress bar of a video, you'll see a thumbnail for that time frame, just like YouTube. And similar to YouTube, you'll also be able to drag your cursor (or finger, depending upon your input mechanism) to scrub through the video while seeing thumbnail previews. This is a very useful capability that feels long overdue. When trying to locate a specific scene in a video, you no longer need to guess the approximate time, you can simply use thumbnail previews to sift through the video and reach your desired frame. There is a big caveat, though. Thumbnail previews in Google Drive videos are just available for newly uploaded content. There is no way to leverage the feature on the videos currently present in your Drive library. If you have turned on automatic backups to Drive through your Android phone or are just a Drive user in general, you likely have hundreds, if not thousands, of videos in your library. However, there is no way to enable thumbnail previews on any of them. In terms of rollout, this capability is now being made available to all Google Workspace customers, Google Workspace Individual subscribers, and personal Google accounts over the next few days. There is no way for Google Workspace admins to disable the feature from their side.
    • ..."both powered by Intel's latest Core Ultra 200 Series processors"
  • Recent Achievements

    • Week One Done
      SmileWorks Dental earned a badge
      Week One Done
    • Community Regular
      vZeroG went up a rank
      Community Regular
    • Collaborator
      Snake Doc earned a badge
      Collaborator
    • Week One Done
      Snake Doc earned a badge
      Week One Done
    • One Month Later
      Johnny Mrkvička earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      583
    2. 2
      Michael Scrip
      199
    3. 3
      ATLien_0
      196
    4. 4
      +FloatingFatMan
      129
    5. 5
      Xenon
      123
  • Tell a friend

    Love Neowin? Tell a friend!