How do I Replace Special Letters ex. tres niños to tres ninos.

1 favourites
  • 2 posts
From the Asset Store
A collection of various soldier character sprites for creating a 2D platformer or sidescroller game
  • if i have 1000+ words as in spanish

    in the global variable

    SpanishWord = tres niños

    so i want to replace special letters and set as "tres ninos"

    i try script

    // Retrieve the value from the global variable 'SpanishWord'

    var text = runtime.getGlobalVariable("SpanishWord").getValue();

    // Define character mappings for conversion

    var charMap = {

    'í': 'i',

    'á': 'a',

    'é': 'e',

    'ó': 'o',

    'ú': 'u',

    'ñ': 'n',

    // Add other mappings as needed

    };

    // Function to replace characters based on the map

    function convertText(text) {

    return text.replace(/[íáéóúñ]/g, function(match) {

    return charMap[match] || match;

    });

    }

    // Convert the text

    var convertedText = convertText(text);

    // Set the converted text into the global variable 'spash'

    runtime.getGlobalVariable("spash").setValue(convertedText);

    but getting error

    please guide me right ans..

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Why are you using scripting for that?

    Set text to replace(text, "í", "i")

    Set text to replace(text, "á", "a")

    Or you can nest them:

    Set text to replace(replace(text, "á", "a"), "í", "i")

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)