L
L
Lord Drous2016-12-08 20:15:53
Programming
Lord Drous, 2016-12-08 20:15:53

Remove all "*" and duplicate every character other than the given digit if it is present in the original string?

b1b95cb1c4d044c4abf9e00cd1feb718.pngHello, I was asked to solve such a problem, while my program can only remove asterisks, but now I don’t understand the conditions “different from the given number”, no input data is given, please help with the solution, maybe someone has come across

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Fedoryan, 2016-12-09
@LorDDrouS

Sub duplicate()
    Dim StrIn As String
    Dim StrOut As String
    Dim Symbol As String
    Dim Twice As Boolean
    
    StrIn = "835*23*2"
    Symbol = "2"
    StrOut = ""
    
    If InStr(StrIn, Symbol) > 0 Then
        Twice = True
    Else
        Twice = False
    End If
    
    For i = 1 To Len(StrIn)
        Char = Mid(StrIn, i, 1)
        Select Case Char
            Case Symbol
                StrOut = StrOut & Char
            Case "*"
                StrOut = StrOut
            Case Else
                StrOut = StrOut & Char
                If Twice Then
                    StrOut = StrOut & Char
                End If
        End Select
    Next i
    
    MsgBox (StrOut)
End Sub

X
x67, 2016-12-09
@x67

Well, it's all written. The computer only needs to translate from Russian into binary. Of course, you don’t understand binary, but you can talk to the compiler in some other language, explaining to him the essence. And he'll figure it out for sure
there is no given number, so you need to teach the computer to set it. We choose the number. To hint about this to the computer, you can use entering a number through the command line.
Further, we act only if the digit is in the source string. We perform the check letter by letter or in its entirety (if there is a function or procedure that can do this). If found, then you need to understand, what does it mean to duplicate? Just instead of one letter in the line should be two? Or just display these letters on the screen? I think the first option. Suppose we cannot dynamically set the length. Well, then we consider the number of characters in the line, excluding the given number. Multiply by two - this will be the length of the new line.
And now we sequentially copy all the characters except for the given number twice into a new line. And that's it .. Problems? Shouldn't be a problem. Unless there will be options on how to implement the last actions - it depends on the capabilities of the language and your ability to build algorithms. Generally decide. If you decide for yourself, you will do well and pass the coursework / test / copy exactly by 5.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question