Easy problem for most of you very hard for me
Easy problem for most of you very hard for me
Hey, i want to make a programm where you can typ a text in and it swaps every letter (every a, b ,c and so on) vom the input text with every letter from a to z but i dont know how to make this, maybe one of you can help me i´m trying it for hours.
(Yes I´m started to learn just a few days ago but need this for school)
Hope for a nice tipp or solution
(Yes I´m started to learn just a few days ago but need this for school)
Hope for a nice tipp or solution
Re: Easy problem for most of you very hard for me
Show us some code worked out by you and we will try to help you to complete the task 

ThinkPad T61 | PureBasic 4.51 | Windows 7 (32) | Kubuntu 11.10 (64) | Syllable (32)
Re: Easy problem for most of you very hard for me
Code: Select all
Procedure SubClassCB(hWnd, uMsg, wParam, lParam)
Protected oldproc = GetProp_(hWnd, "oldproc")
Select uMsg
Case #WM_NCDESTROY
RemoveProp_(hWnd, "oldproc")
Case #WM_CHAR
wParam + 1
EndSelect
ProcedureReturn CallWindowProc_(oldproc, hWnd, uMsg, wParam, lParam)
EndProcedure
Procedure SubClassGadget(ID)
Protected oldproc = SetWindowLongPtr_(GadgetID(ID), #GWL_WNDPROC, @SubClassCB())
ProcedureReturn SetProp_(GadgetID(ID), "oldproc", oldproc)
EndProcedure
OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "")
EditorGadget(0, 5, 5, 630, 470)
SubClassGadget(0)
SetActiveGadget(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Easy problem for most of you very hard for me
started with:
test$ = "Sven"
ReplaceString(test$, "S", "H", #PB_String_InPlace, 1)
Debug test$
because for me it was the only good command I found in the reference, but i can´t add more letters like:
test$ = "Sven"
ReplaceString(test$, "S +, V", "H ,+ B", #PB_String_InPlace, 1)
Debug test$
or
test$ = "Sven"
ReplaceString(test$, "S", "H","V", "B", #PB_String_InPlace, 1)
Debug test$
Becaus I thought that this is the right way to add more solutions. But this just make my debugger pop up. I believ that I just have to know how to let the programm change every eg. "a" with all letters, cause than i would try so long till there is a solution. But now there is no solution for me
test$ = "Sven"
ReplaceString(test$, "S", "H", #PB_String_InPlace, 1)
Debug test$
because for me it was the only good command I found in the reference, but i can´t add more letters like:
test$ = "Sven"
ReplaceString(test$, "S +, V", "H ,+ B", #PB_String_InPlace, 1)
Debug test$
or
test$ = "Sven"
ReplaceString(test$, "S", "H","V", "B", #PB_String_InPlace, 1)
Debug test$
Becaus I thought that this is the right way to add more solutions. But this just make my debugger pop up. I believ that I just have to know how to let the programm change every eg. "a" with all letters, cause than i would try so long till there is a solution. But now there is no solution for me
Re: Easy problem for most of you very hard for me
Sven (or Szven),
Nobody understood what you were trying to accomplish. You have to be very clear with what you want to do. You said: [... and it swaps every letter]. How swapped? There are many ways and directions to swap!
From your attempt, I finally understood that you want to swap the whole alphabet, so that when you type the letter A, you want to see the letter Z on the screen, and when you type a B, Y should be displayed and so on.
I guessed it solely with the letters S and H you showed in your attempt, and indeed, S is the 8th letter of the alphabet, counted from Z, like the H which is also the 8th letter!
And because you are very new in programming, try to understand the logic with a simple table.

Nobody understood what you were trying to accomplish. You have to be very clear with what you want to do. You said: [... and it swaps every letter]. How swapped? There are many ways and directions to swap!
From your attempt, I finally understood that you want to swap the whole alphabet, so that when you type the letter A, you want to see the letter Z on the screen, and when you type a B, Y should be displayed and so on.
I guessed it solely with the letters S and H you showed in your attempt, and indeed, S is the 8th letter of the alphabet, counted from Z, like the H which is also the 8th letter!

And because you are very new in programming, try to understand the logic with a simple table.
Code: Select all
Table1$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; the normal alphabet
Table2$="ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"; the reversed alphabet
Test$="Sven is the best at school !"; the word that you want to "swap"
For i=1 To Len(Test$); we make a loop for each letter in Test$
Pos=FindString(Table1$,Mid(Test$,i,1)); we get the position of the letter in the normal alphabet (Table1$)
If Pos=0; if the letter is not found
New$=New$+Mid(Test$,i,1); we put the same letter or symbol in the new word
Else
New$=New$+Mid(Table2$,Pos,1); we put the corresponding letter in the new word
EndIf
Next
Debug New$; and finally we want to see the new word!

- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: Easy problem for most of you very hard for me
Since there may be "solution" replies, it would be helpful if the topic reflected the actual problem for which solutions may be suggested.
This will help any future searches.
This will help any future searches.

Re: Easy problem for most of you very hard for me
here is a little trick, only work for ascii and no caps.
Code: Select all
define str.s = "abcdef"
define *ptr = @str
repeat
pokeb( *ptr, 122 - ( peekb( *ptr ) - 97 ) )
*ptr+1
until peekc(*ptr) = 0
debug str
Re: Easy problem for most of you very hard for me
A little variation on the code above that works for both upper and lowercase characters
Code: Select all
Define str.s = "Abcdef Gh"
Define *ptr.Character = @str
While *ptr\c
If *ptr\c & 64
*ptr\c = *ptr\c ! 31 - 4
EndIf
*ptr + SizeOf(Character)
Wend
Debug str
Re: Easy problem for most of you very hard for me
"Easy problem for most of you very hard for me"
Great example of a bad title for a post. Can you guess why ? Try.
Great example of a bad title for a post. Can you guess why ? Try.
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review