Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:49:33+00:00 2026-05-30T17:49:33+00:00

I want to select a random space in a string and replace it with

  • 0

I want to select a random space in a string and replace it with a word (%word%) but there is a problem. The position cannot be fixed as i want it to be inserted at a random break. Few things which iam considering :

1)break the string at a space and merge it with the word
2) find a random space and replace it with the word. I like this point and so far all i have is break the selectedtext into string array and then iterate over each line. But i don’t know how to find a random string position? Any short and sweet code please?

  If (rtfArticle.SelectedText.Length > 0) Then
        Dim strArray As String() = rtfArticle.SelectedText.Split(New Char() {ChrW(10)})
        For Each str3 As String In strArray
            If (str3.Contains(" ") = True) Then

            End If
        Next
    End If
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:49:34+00:00Added an answer on May 30, 2026 at 5:49 pm

    You could locate the spaces in the string, pick one by random, and replace it. Something like:

    ' Get string
    Dim data As String = rtfArticle.SelectedText
    ' Get space positions
    Dim spaces As New List(Of Integer)
    For i As Integer = 0 to data.Length - 1
      If data(i) = " "C Then spaces.Add(i)
    Next
    ' Get a random space
    Dim rnd As New Random()
    Dim pos As Integer = spaces(rnd.Next(spaces.Length))
    ' Remove the space
    data = data.Remove(pos, 1)
    ' Insert the replacement
    data = data.Insert(pos, "%word%")
    ' Put the string back
    rtfArticle.SelectedText = data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to select a random value from a array, but keep it unique
Is there some way of dynamically creating keywords. I want to select random words
With Perl's WWW::Mechanize module, I want to select a random value from a select
I want to write a map/reduce job to select a number of random samples
I want to SELECT a formatted date string from a datetime type in SQL
I want to select a token out of a string if it exists in
I have one table and I want to select 10 rows randomly. But I
Hi all, My requirement is simple.I want to select random rows from a table.
i want to select first 10 rows then select 5 random rows of them.
I have a multi-line variable and want to select a random line: $.get('namelist.txt', function(nameList)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.