Text Concatenation


Concatenation is an operation that can be applied to text. The operator += is implemented by wstring to concatenate text. The example below creates a wstring variable called text. The variable begins with the text "Micro" and appends several words.
La concatenación es una operación que puede ser aplicada a texto. El operador += es implementado por wstring para concatenar texto. El ejemplo mostrado debajo crea una variable wstring llamada text. La variable comienza con la palabra "Micro" y se le concatenan varias palabras.


In the example below the variable text of type wchar_t has a capacity to store a maximum of 128 characters. The command wcscpy_s copies the word "Micro" to the variable called text. The command wcscat_t appends some words to the same variable.
En el ejemplo de abajo la variable text del tipo wchar_t tiene una capacidad para almacenar un máximo de 128 letras. El comando wcscpy_s copia la palabra "Micro" a la variable llamada text. El comando wcscat_t le pega algunas palabras a la misma variable.


In the previous example, the variable called text can hold a maximum of 127 letters because the NULL terminator has to be included after the last letter of the text. Additionally, it is very important to be sure that the variable has enough capacity to hold all the text.
En el ejemplo previo, la variable llamada text puede almacenar un máximo de 128 letras porque el terminador nulo tiene que ser incluido después de la última letra del texto. Adicionalmente, es muy importante asegurarse que la variable tiene suficiente capacidad para almacenar todo el texto.

Problem 1.
Create a Wintempla project called Sentence to create a sentence as shown.
Cree un proyecto de Wintempla llamado Sentence para crear una frase como se muestra.


void Sentence::btCreate_Click(Win::Event& e)
     const wstring name = tbxName.Text;
     const wstring verb = tbxVerb.Text;
     wstring sentence = name;
     sentence += L" likes ";
     sentence += verb;
     tbxOutput.Text = sentence;

Problem 2
Repeat the previous problem using Win32 only (without Wintempla).
Repita el problema previo usando solamente Win32 (sin Wintempla).


//_________________________________________________ Sentence32.cpp
#include "stdafx.h"
#include "Sentence32.h"
#include <string>
using namespace std;

INT_PTR Window_Open(HWND hWnd, WPARAM wParam, LPARAM lParam)
     ::SetWindowText(hWnd, L"Sentence32");
     return TRUE;

INT_PTR btCreate_Click(HWND hWnd, WPARAM wParam, LPARAM lParam)
     //_______________________________ Extract Name
     wchar_t name[128];
     ::GetWindowText(::GetDlgItem(hWnd, ID_TBX_NAME), name, 128);
     //_______________________________ Extract Verb
     wchar_t verb[128];
     ::GetWindowText(::GetDlgItem(hWnd, ID_TBX_VERB), verb, 128);
     wstring sentence = name;
     sentence += L" likes ";
     sentence += verb;
     ::SetWindowText(::GetDlgItem(hWnd, ID_TBX_OUTPUT), sentence.c_str());
     return TRUE;

INT_PTR CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     switch (message)
     case WM_INITDIALOG:
          return Window_Open(hWnd, wParam, lParam);
     case WM_COMMAND:
          if (LOWORD(wParam) == ID_BT_CREATE) return btCreate_Click(hWnd, wParam, lParam);
          if (LOWORD(wParam) == IDCANCEL) ::EndDialog(hWnd, 0);
     return (INT_PTR)FALSE;

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int cmdShow)
     ::DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, WndProc);
     return 0;

Problem 3
javaRepeat the previous problem in Java called your project SentenceJ.
javaRepita el problema previo en Java llame a su proyecto SentenceJ


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SentenceJ extends JFrame implements ActionListener
     private JTextField tbxName;
     private JTextField tbxVerb;
     private JTextField tbxOutput;
     private JButton btCreate;

     public SentenceJ()
          Container pane = this.getContentPane();
          pane.setLayout(new FlowLayout());
          //______________________________________________ tbxName
          tbxName = new JTextField(10);
          //______________________________________________ likes
          pane.add(new JLabel("likes"));
          //______________________________________________ tbxVerb
          tbxVerb = new JTextField(10);
          //______________________________________________ btCreate
          btCreate = new JButton("Create");
          //______________________________________________ tbxOutput
          tbxOutput = new JTextField(20);

     public void actionPerformed(ActionEvent e)
          if (e.getSource() == btCreate)
               final String name = this.tbxName.getText();
               final String verb = this.tbxVerb.getText();
               String sentence = name + " likes " + verb;

     public static void main(String[] args)
          SentenceJ frame = new SentenceJ();


The STL provides the template classe wstring (string) to manipulate strings in C++. You should review all methods of this class. The example below shows how to use the method assign to copy some text from one variable to another one.
La STL proporciona la clases plantilla wstring (string) para manipular texto en C++. Usted debería revisar los métodos de esta clase. El ejemplo de abajo muestra cómo usar el método assign para copiar texto de una variable a otra.

wstring first_name;
wstring last_name;
const wchar_t * name = L"Peter Edwards";

first_name.assign(name, 0, 5); // Peter
last_name.assign(name, 6, 8); // Edwards

Problem 4
Repeat the previous problem in C# called your project SentenceS.
Repita el problema previo en C# llame a su proyecto SentenceS.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SentenceS
     public partial class Form1 : Form
          public Form1()

          private void btCreate_Click(object sender, EventArgs e)
               //_____________________________________________________ Method 1
               String name = tbxName.Text;
               String verb = tbxVerb.Text;
               String sentence = name;
               sentence += " likes ";
               sentence += verb;
               tbxOutput.Text = sentence;
               //_____________________________________________________ Method 2
               //String name = tbxName.Text;
               //String verb = tbxVerb.Text;
               //StringBuilder sentence = new StringBuilder(name);
               //sentence.Append(" likes ");
               //tbxOutput.Text = sentence.ToString();


© Copyright 2000-2019 Wintempla selo. All Rights Reserved. Sep 05 2019. Home