Author Topic: String Manip  (Read 315 times)

Legacy_Tiggers.no.tail

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +0/-0
String Manip
« on: July 02, 2011, 07:18:59 pm »


                I was browsing through the lexicon for some string manipulation functions. I'm wondering if there's an easy way that I can get the players first name and last name by looking for the first space in the string (assuming they dont put something like John Claude Van Dam). Is such a thing possible to do purely from a script?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
String Manip
« Reply #1 on: July 02, 2011, 07:25:41 pm »


               #include "x3_inc_string"

void main()
{
  object oPC= GetFirstPC();
  string sFullName = GetName(oPC);
  string sFirstName = StringParse(sFullName);
  string sLastName = StringRemoveParsed(sFullName,sFirstName);
}
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
String Manip
« Reply #2 on: July 02, 2011, 07:35:41 pm »


               The best way is with nwnx, using dragonsong's nwnx_letoscript or acaos' nwnx_funcs. Either can retrieve first and last individually. Past that, it's impossible to do with complete confidence, because you never know what characters the player has used in his name. I think there are a few sample attempts floating around the old bioboards - you might have a look with the omnibus. None of them will work correctly 100% of the time like the nwnx solutions, though.

[Edit]
I see LF beat me to the punch. the x3 include just looks for the space, which won't always work.

Funky
               
               

               


                     Modifié par FunkySwerve, 02 juillet 2011 - 06:37 .
                     
                  


            

Legacy_Tiggers.no.tail

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +0/-0
String Manip
« Reply #3 on: July 02, 2011, 07:45:29 pm »


               Well as long as it works most the time.