So I have a property table that has addresses like below.

12 Andrews CL, Pxxx
1/12 Andrews CL, Pxxx
2/31 Macrossan ST, Pxxx
2/7-11 Barrier   ST, Pxxx

I need to only show


Can this be done within the expression builder in Mapinfo 12?

In python it would be something like address[:address.find(' ')]


Yes, you can do this by using the Left$ and InStr functions as below. Check out the MapBasic Reference Guide (should be available in the Documentation folder of your MapInfo installation) for detailed information about those functions, along with a whole host of others.

Left$(address,InStr(1, address, " ") - 1)
  • You beat me to it by a few seconds, @T_Bacon :-) – Peter Horsbøll Møller Feb 24 '16 at 13:55
  • So whose answer should I pick? you both answered the same but neither of them get all characters from the left up to the first space. Thanks for pointing me to the reference guide. I didn't know it was there. – GeorgeC Feb 24 '16 at 14:42
  • 2
    Pick this one as he posted the answer seconds before me ;-) – Peter Horsbøll Møller Feb 24 '16 at 14:55
  • No worries -but how do I get to print the first characters upto the first space? – GeorgeC Feb 24 '16 at 15:22
  • 1
    @GeorgeC - Or you could do it through MapBasic as Peter has suggested in the comments for his answer. – T_Bacon Feb 24 '16 at 16:07

Try this:

Left$(ADDRESS, (InStr(1, ADDRESS, " ") - 1))

This will show the string to the left of the first space characters. ADDRESS is here the name of the column

  • Thanks. It is printing Pxxx rather than 1/12. I want it to print from the first character upto the first space character. – GeorgeC Feb 24 '16 at 14:38
  • Are you saying it's printing the characters from the right instead of the characters from the left? – Peter Horsbøll Møller Feb 24 '16 at 14:56
  • Is the perceived space in fact a tab character by any chance? Try changing this bit: InStr(1, ADDRESS, " ") to InStr(1, ADDRESS, Chr$(9)), that might fix it. – T_Bacon Feb 24 '16 at 14:57
  • So if the full address is "1/12 Davidson ST, PORT SMITH" it is printing "Port" but it should print 1/12. How do I tell if it is a tab? it's all in one address field as {1/12 Davidson ST, PORT SMITH} – GeorgeC Feb 24 '16 at 15:00
  • 1
    Try this to figure out what character it is: select the object in the map and run these two statements via the MapBasic window which will print the ascii# of the character to the message window. The number 5 refers to the character you want to inspect: Fetch First From Selection Print Asc(Mid$(ADDRESS, 5, 1)) – Peter Horsbøll Møller Feb 24 '16 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.