HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] replace character in a string?  (Read 981 times)

Arlohian

  • General Accounts
  • *
  • Posts: 43
    • View Profile
[Resolved] replace character in a string?
« on: Jul 22, 12, 08:32:52 AM »

Hi

I'm wondering what method would be the most efficient in replacing a single predetermined character in a long string, ex an "talent tree description" as seen in many games... that needs to change its text depending on how many points you have in that specific perk.

so on a client side script shows a window with:
...deals @ magic damage to & targets...
where i would replace @ for like 30 and & for 3

Currently the only method i can think of is tokenize the string then check each token if its the right character, once it finds it, it replaces it and then glues it all together again.

Is there another way? Or will it work just fine anyway? id prefer to keep it in a single GUILabel because the string's length will vary a lot.

Any help is greatly appreciated :)
« Last Edit: Nov 02, 12, 11:06:02 PM by HE-Cooper »
Logged
Fledgling programmer

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: replace character in a string?
« Reply #1 on: Jul 22, 12, 10:44:56 AM »

There is an external function called ReplaceString() that will do that.  The string passed in is left alone and the result is passed back as a return value.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

Arlohian

  • General Accounts
  • *
  • Posts: 43
    • View Profile
Re: replace character in a string?
« Reply #2 on: Jul 22, 12, 04:59:46 PM »

Thanks :D

Looked in wiki and forum but again forgot about the external functions...
Works perfect.
Logged
Fledgling programmer