Results 1 to 8 of 8

Thread: [RESOLVED] Insert same repeated characters among words

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Posts
    230

    Resolved [RESOLVED] Insert same repeated characters among words

    Hi,
    I have extracted some words with fixed length -
    Code:
    "liked years mouth click width exams forms genda coder codes table poorl poste franc repot derie cvang"
    and I want to insert some characters among them (, and T), but what I wannt is that theres need to be placed repeatedly using this pattern:
    Code:
    "liked,years,mouth,clickTwidthTexamsTforms,genda,coder,codesTtableTpoorlTposte,franc,repot,derieTcvang"
    Last edited by VB.NET Developer; Feb 27th, 2021 at 12:02 PM.
    Please dont forget to add good reputation if my advices were useful for you.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,851

    Re: Insert same repeated characters among words

    Code:
    TextBox1.Text = TextBox1.Text.Re[;ace("liked years mouth click width exams forms genda coder codes table poorl poste franc repot derie cvang", "liked,years,mouth,clickTwidthTexamsTforms,genda,coder,codesTtableTpoorlTposte,franc,repot,derieTcvang")

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Posts
    230

    Re: Insert same repeated characters among words

    Thanks, but this is not exaclty I am looking for...
    I am looking for something that could be changed according to my needs (separator length, characters to replace), because I have another texts, but on these I need to use different character set as a replacement...
    Please dont forget to add good reputation if my advices were useful for you.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,557

    Re: Insert same repeated characters among words

    Quote Originally Posted by VB.NET Developer View Post
    I am looking for something that could be changed according to my needs
    So something other than what you actually asked for in the first post then? Perhaps you should provide all the relevant information up front. That way, we won't be forced to guess or assume and then we can't guess or assume incorrectly. Don't just provide a single example because there are always going to be lots of ways that one example could be handled. What we need is the actual rules you want implemented, not an example of those rules implemented. In short, provide a FULL and CLEAR description of the problem.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Posts
    230

    Re: Insert same repeated characters among words

    OK. I have many other words such as
    "no to te be dc cu nt wi at de cz cm de re wo id st ri gp" etc
    on these I want to insert different character set - "." and "3"
    so output will looks like this:
    "no.to.te.be.dc3cu3nt3wi3at.de.cz.cm.de3re3wo3id3st.ri.gp" etc

    Another example:
    "three fourth space reply quote salut words exeed toped cruze cajow" etc
    on these I want to use another character set - "?" and "@"
    "three?fourth@space?reply@quote?salut@words?exeed@toped?cruze@cajow"

    So I am looking for universal solution that can be configured with parameters - separators, length. So basically replace space with repeated set of characters according the pattern.
    Please dont forget to add good reputation if my advices were useful for you.

  6. #6
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,725

    Re: Insert same repeated characters among words

    I've read you Post(s) 4 times and still don't get it.

    a guess would be to use Skip and Take in a Loop

    quick samle (without Loop)
    Code:
            Dim input As String = "liked years mouth click width exams forms genda coder codes table poorl poste franc repot derie cvang"
    
            Dim allWords = input.Split(New Char() {" "c})
    
            Dim a = allWords.Skip(3).Take(4)
    
            Debug.WriteLine(String.Join("T", a))
    
    'returns:
    'clickTwidthTexamsTforms
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  7. #7
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    575

    Re: Insert same repeated characters among words

    Quote Originally Posted by VB.NET Developer View Post
    OK. I have many other words such as
    "no to te be dc cu nt wi at de cz cm de re wo id st ri gp" etc
    on these I want to insert different character set - "." and "3"
    so output will looks like this:
    "no.to.te.be.dc3cu3nt3wi3at.de.cz.cm.de3re3wo3id3st.ri.gp" etc

    Another example:
    "three fourth space reply quote salut words exeed toped cruze cajow" etc
    on these I want to use another character set - "?" and "@"
    "three?fourth@space?reply@quote?salut@words?exeed@toped?cruze@cajow"

    So I am looking for universal solution that can be configured with parameters - separators, length. So basically replace space with repeated set of characters according the pattern.
    what is the logic of your sequences ?
    on the first example in post #1, the sequence of replacement is 3 x ',' then 3 x 'T' and so on
    on the the two examples above, the first one is 4 x '.' then 4 x '3', ...
    on the third it is 1 x '?' then 1 x '@'....
    is there other potential sequences ? (3 characters, different length for each ?)
    you will need 1 variable for the length of the sequence, 2 variables for the character.
    a "for each" loop to go through all character and a counter to change the character.
    you check each character, if it is a space, change the space, increase the counter, if the counter reach the limit, change the replacement character and put the counter to 0, etc...
    you put all that in a function : input : string, length, char1, char2. output : string
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2018
    Posts
    230

    Re: Insert same repeated characters among words

    what is the logic of your sequences ?
    is there other potential sequences ? (3 characters, different length for each ?)
    As I said prior - I am looking for universal solution that can be configured with parameters - separators, length. So basically replace space with repeated set of characters according the pattern.

    I figured it out some days ago:

    Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Dim StrData As String
            StrData = TextBox4.Text
            StrData = Replace(StrData, " ", ",", , TextBox_K.Text)
            StrData = Replace(StrData, " ", "T", , TextBox_P.Text)
            TextBox4.Text = StrData
        End Sub
    Last edited by VB.NET Developer; Mar 16th, 2021 at 01:05 PM. Reason: fixed errors in code
    Please dont forget to add good reputation if my advices were useful for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width